#include #include using namespace std; using namespace atcoder; using ll = long long; using ld = long double; using ull = unsigned long long; using Graph = vector>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define NP next_permutation const int INF32 = 2e9; const ll INF64 = 2e18; const ll mod = 998244353; // const ll mod = 1e9 + 7; template bool chmin(T &a, T b){if(a > b){a = b; return true;} return false;} template bool chmax(T &a, T b){if(a < b){a = b; return true;} return false;} void cincout() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); } ll Pow(ll a, int b) { ll ret = 1; for (int i = 0; i < b; i++) ret *= a; return ret; } int main() { cincout(); ll K, N; cin >> K >> N; map already; ll ans = 0; for (ll x = 1; Pow(x, 6) <= N; x++) { for (ll y = 1; Pow(x, 6) + Pow(y, 4) <= N; y++) { ll sum = Pow(x, 6) + Pow(y, 4); if (sum % K != 0) continue; ll ok = 0; ll ng = 4e7; while (abs(ok - ng) > 1) { ll mid = (ok + ng) / 2; (mid * mid <= sum / K ? ok : ng) = mid; } if (ok * ok == sum / K && !already[sum / K]) { already[sum / K] = true; ans++; } } } cout << ans << endl; }