fork download
  1. #include<bits/stdc++.h>
  2. #define ull unsigned long long
  3. #define ll long long
  4. #define all(x) x.begin(), x.end()
  5. using namespace std;
  6. const int maxn = 1e6 + 5;
  7. bool checkCP(int n) {
  8. int k = sqrt(n);
  9. if (k * k == n) return true;
  10. return false;
  11. }
  12. unordered_map<int, int> D;
  13. void div(int n) {
  14. for (int i = 2; i <= sqrt(n); ++i) {
  15. if (n % i == 0) {
  16. while (n % i == 0) {
  17. n /= i;
  18. D[i]++;
  19. }
  20. }
  21. }
  22. if (n > 1) D[n]++;
  23. }
  24. int main() {
  25. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  26. ll n, x;
  27. ll cnt = 0;
  28. cin >> n >> x;
  29. if (n <= 1e6) {
  30. for (ll i = 1; i <= n; ++i) {
  31. if (checkCP(x * i)) {
  32. cnt++;
  33. }
  34. }
  35. cout << cnt;
  36. }
  37. else
  38. {
  39. div(x);
  40. ll Y = 1;
  41. for(auto it:D){
  42. if(it.second % 2 == 1){
  43. Y *= it.first;
  44. }
  45. }
  46. ll res = sqrt(n/Y);
  47. cout<<res;
  48. }
  49.  
  50. }
  51.  
  52.  
Success #stdin #stdout 0.01s 5284KB
stdin
200 12
stdout
8