#include using namespace std; using ull = unsigned long long; using u128 = unsigned __int128; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ull K, N; if (!(cin >> K >> N)) return 0; /* x^6, y^4 を前計算 */ vector pow6, pow4; for (ull x = 1;; ++x) { u128 v = (u128)x * x * x * x * x * x; if (v > N) break; pow6.push_back((ull)v); } for (ull y = 1;; ++y) { u128 v = (u128)y * y * y * y; if (v > N) break; pow4.push_back((ull)v); } unordered_set good; good.reserve(pow6.size() * 8); // ざっくり確保 for (ull a : pow6) { for (ull b : pow4) { ull s = a + b; if (s > N) break; // b は単調増加 if (s % K) continue; ull q = s / K; // = z^2 になるか? ull z = sqrtl((long double)q); // 近似 while ((u128)(z + 1) * (z + 1) <= q) ++z; while ((u128)z * z > q) --z; if ((u128)z * z == q) good.insert(s); } } cout << good.size() << '\n'; return 0; }