結果
問題 | No.2187 三立法和 mod 333 |
ユーザー |
![]() |
提出日時 | 2023-01-14 16:32:22 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,542 bytes |
コンパイル時間 | 1,765 ms |
コンパイル使用メモリ | 195,040 KB |
最終ジャッジ日時 | 2025-02-10 03:31:13 |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 12 TLE * 21 |
ソースコード
#include<bits/stdc++.h>#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)#define rep(i,a,b) for(int i=int(a);i<int(b);++i)#define All(x) (x).begin(),(x).end()#define rAll(x) (x).rbegin(),(x).rend()using namespace std;using ll = long long;std::pair<ll,ll> bisearch(ll l,ll r,std::function<bool(ll)> f){while((l+1)<r){ll m=(l+r)/2;if(f(m)) r=m;else l=m;}return std::make_pair(l,r);}constexpr int mod = 333;ll cnt[4445][mod]; // iまでにz^3がj mod 333であるような数ll p4[4445];ll p3[4445];ll p3m[4445];int main(){int a;cin>>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 1for(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";}#endifcout << ans << endl;}