#include #define REP(i,n) for(int i=0,i##_len=int(n);i bisearch(ll l,ll r,std::function f){ while((l+1)>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; for(int y = x; y < 4444; y++) { int z3 = (a + 2 * mod - (p3m[x] + p3m[y]))%mod; if(cnt[4444][z3] <= 0) continue; ll zmax = p4[4444] - p4[x] - p4[y]; if(zmax <= 0) break; zmax = bisearch(0, 4444, [&](int idx){return p4[idx] > zmax;}).first; int c = cnt[zmax][z3]; //if(c > 0 && cnt[4444][z3] == 0) cerr << x << " " << y << " " << zmax << " " << z3 << " " << c << endl; if(y==x) ans += c; else ans2 += c; } ans += 2 * ans2; //cerr << x << "\n"; } #endif cout << ans << endl; }