#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define all(x) x.begin(), x.end()
using namespace std;
const int maxn = 1e6 + 5;
bool checkCP(int n) {
int k = sqrt(n);
if (k * k == n) return true;
return false;
}
unordered_map<int, int> D;
void div(int n) {
for (int i = 2; i <= sqrt(n); ++i) {
if (n % i == 0) {
while (n % i == 0) {
n /= i;
D[i]++;
}
}
}
if (n > 1) D[n]++;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll n, x;
ll cnt = 0;
cin >> n >> x;
if (n <= 1e6) {
for (ll i = 1; i <= n; ++i) {
if (checkCP(x * i)) {
cnt++;
}
}
cout << cnt;
}
else
{
div(x);
ll Y = 1;
for(auto it:D){
if(it.second % 2 == 1){
Y *= it.first;
}
}
ll res = sqrt(n/Y);
cout<<res;
}
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KI2RlZmluZSB1bGwgdW5zaWduZWQgbG9uZyBsb25nCiNkZWZpbmUgbGwgbG9uZyBsb25nCiNkZWZpbmUgYWxsKHgpIHguYmVnaW4oKSwgeC5lbmQoKQp1c2luZyBuYW1lc3BhY2Ugc3RkOwpjb25zdCBpbnQgbWF4biA9IDFlNiArIDU7CmJvb2wgY2hlY2tDUChpbnQgbikgewogICAgaW50IGsgPSBzcXJ0KG4pOwogICAgaWYgKGsgKiBrID09IG4pIHJldHVybiB0cnVlOwogICAgcmV0dXJuIGZhbHNlOwp9CnVub3JkZXJlZF9tYXA8aW50LCBpbnQ+IEQ7CnZvaWQgZGl2KGludCBuKSB7CiAgICBmb3IgKGludCBpID0gMjsgaSA8PSBzcXJ0KG4pOyArK2kpIHsKICAgICAgICBpZiAobiAlIGkgPT0gMCkgewogICAgICAgICAgICB3aGlsZSAobiAlIGkgPT0gMCkgewogICAgICAgICAgICAgICAgbiAvPSBpOwogICAgICAgICAgICAgICAgRFtpXSsrOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQogICAgaWYgKG4gPiAxKSBEW25dKys7Cn0KaW50IG1haW4oKSB7CiAgICBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKDApOyBjaW4udGllKDApOyBjb3V0LnRpZSgwKTsKICAgIGxsIG4sIHg7CiAgICBsbCBjbnQgPSAwOwogICAgY2luID4+IG4gPj4geDsKICAgIGlmIChuIDw9IDFlNikgewogICAgICAgIGZvciAobGwgaSA9IDE7IGkgPD0gbjsgKytpKSB7CiAgICAgICAgICAgIGlmIChjaGVja0NQKHggKiBpKSkgewogICAgICAgICAgICAgICAgY250Kys7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgY291dCA8PCBjbnQ7CiAgICB9CiAgICBlbHNlCiAgICB7CiAgICAgICAgZGl2KHgpOwogICAgICAgIGxsIFkgPSAxOwogICAgICAgIGZvcihhdXRvIGl0OkQpewogICAgICAgICAgICBpZihpdC5zZWNvbmQgJSAyID09IDEpewogICAgICAgICAgICAgICAgWSAqPSBpdC5maXJzdDsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBsbCByZXMgPSBzcXJ0KG4vWSk7CiAgICAgICAgY291dDw8cmVzOwogICAgfQoKfQoK