#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; } ans = 0; ans2 = 0; #if 1 for(int x = 1; x < 4444; x++) { prev_zmax = 4444; zmax_calc = p4[4444] - p4[x]; z3_calc = a + 2 * mod - p3m[x]; for(int y = x; y < 4444; y++) { z3 = (z3_calc - p3m[y]) % mod; if(cnt[4443][z3] == 0) continue; zmax = zmax_calc - p4[y]; if(zmax <= 0) break; left = 1; #if 1 while(prev_zmax > left + 1) { int mid = (left + prev_zmax) >> 1; ((p4[mid] <= zmax) ? left : prev_zmax) = mid; //cerr << left << " " << prev_zmax << endl; } #endif if(y==x) ans += cnt[left][z3]; else ans2 += cnt[left][z3]; } } #endif std::cout << ans + 2 * ans2 << "\n"; }