#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include #define REP(i,n) for(int i=0,i##_len=int(n);i>a; for(ll z = 1; z <= 4444; z++) { ll z3 = z*z*z; REP(i, mod) cnt[z][i] = cnt[z-1][i]; cnt[z][z3%mod]++; p3[z] = z3; p3m[z] = p3[z] % mod; p4[z] = z3*z; } int ans = 0; #if 1 for(int x = 1; x < 4444; x++) { int ans2 = 0; int prev_zmax = 4444; for(int y = x; y < 4444; y++) { int z3 = (a + 2 * mod - (p3m[x] + p3m[y])) % mod; if(cnt[4443][z3] <= 0) continue; ll zmax = p4[4444] - p4[x] - p4[y]; if(zmax <= 0) break; int left = 1; while(prev_zmax > left + 1) { int mid = (left + prev_zmax) >> 1; ((p4[mid] <= zmax) ? left : prev_zmax) = mid; //cerr << left << " " << prev_zmax << endl; } int c = cnt[left][z3]; if(y==x) ans += c; else ans2 += c; } ans += 2 * ans2; //cerr << x << "\n"; } struct Q{ int z3; }; #endif cout << ans << endl; }