#include using namespace std; template bool chmin(T &a,T b){ //a>bならa=bに更新してtrue. if(a > b){a = b; return true;} else return false; } template bool chmax(T &a,T b){ //a T safemod(T a,T m){a %= m,a += m;return a>=m?a-m:a;} //return x = a mod m. template T floor(T a,T b){ //return a/b切り下げ. if(b < 0) a *= -1,b *= -1; return a<0?(a+1)/b-1:a/b; } template T ceil(T a,T b){ //return a/b切り上げ. if(b < 0) a *= -1,b *= -1; return a>0?(a-1)/b+1:a/b; } template pair invgcd(T a,T b){ //return {gcd(a,b),x} (xa≡g(mod b)) a = safemod(a,b); if(a == 0) return {b,0}; T x = 0,y = 1,memob = b; while(a){ T q = b/a; b -= a*q; swap(x,y); y -= q*x; swap(a,b); } if(x < 0) x += memob/b; return {b,x}; } template bool isABmoreC(T a,T b,T c){return a>=ceil(c,b);} //a*b>=c?-> a>=ceil(c/b)?. template bool isABlessC(T a,T b,T c){return a<=floor(c,b);} //同様. template T Kthpower(T a,T k){ //return a^k オーバーフローは考慮しない. T ret = 1; while(k){ if(k&1) ret *= a; a *= a; k >>= 1; } return ret; } template pair Kthpower2(T a,T k){ //return {a^k,オーバーした?} オーバーフローは考慮する. T ret = 1,maxv = numeric_limits::max(); while(k){ if(k&1){ if(isABmoreC(ret,a,maxv) && ret*a != maxv) return {-1,true}; ret *= a; } if(k == 1) break; if(isABmoreC(a,a,maxv) && a*a != maxv) return {-1,true}; a *= a; k >>= 1; } return {ret,false}; } template T Kthroot(T a,T k){ //return floor(a^(1/k)); assert(k > 0 && a >= 0); if(k == 1 || a <= 1) return a; T ret = pow(a,1.0/k); while(true){ auto [check,over] = Kthpower2(ret+1,k); if(over || check > a) break; ret++; } while(true){ auto [check,over] = Kthpower2(ret,k); if(!over && check <= a) break; ret--; } return ret; } int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); long long K,N; cin >> K >> N; set S; for(long long x=1; x*x*x*x*x*x<=N; x++){ long long x6 = x*x*x*x*x*x; for(long long y=1; ; y++){ long long now = x6+y*y*y*y; if(now > N) break; if(now%K) continue; now /= K; long long sq = Kthroot(now,2LL); if(sq*sq != now) continue; S.insert(now); } } cout << S.size() << endl; }