結果
問題 | No.2891 Mint |
ユーザー |
|
提出日時 | 2024-09-30 21:52:36 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,115 bytes |
コンパイル時間 | 1,997 ms |
コンパイル使用メモリ | 120,616 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-09-30 21:52:43 |
合計ジャッジ時間 | 7,526 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 37 WA * 17 |
コンパイルメッセージ
main.cpp: In function 'mint solve(ll, ll)': main.cpp:149:17: warning: 'l' may be used uninitialized [-Wmaybe-uninitialized] 149 | for(ll c=1;c<=l;c++){ | ~^~~ main.cpp:129:8: note: 'l' was declared here 129 | ll l,r; | ^
ソースコード
#include<iostream> #include<string> #include<queue> #include<vector> #include<cassert> #include<random> #include<set> #include<map> #include<cassert> #include<unordered_map> #include<bitset> #include<numeric> #include<algorithm> using namespace std; typedef long long ll; const int inf=1<<30; const ll INF=1LL<<62; typedef pair<int,int> P; typedef pair<int,P> PP; const ll MOD=998244353; const int mod = 998244353; struct mint { long long x; // typedef long long long long; mint(long long x=0):x((x%mod+mod)%mod){} mint operator-() const { return mint(-x);} mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint& operator-=(const mint a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;} mint operator+(const mint a) const { return mint(*this) += a;}//後ろのconstはメンバxを変更しないことを示す mint operator-(const mint a) const { return mint(*this) -= a;} mint operator*(const mint a) const { return mint(*this) *= a;} bool operator==(const mint a) const {return a.x==x;} bool operator!=(const mint a) const {return a.x!=x;} mint pow(unsigned long long int t) const { assert(t>=0); if (!t) return 1; //aがtで割り切れない場合には t%=(mod-1)をして良い mint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod-2);} mint& operator/=(const mint a) { return *this *= a.inv();} mint operator/(const mint a) const { return mint(*this) /= a;} }; std::istream& operator>>(std::istream& is, mint& a) { return is >> a.x;} std::ostream& operator<<(std::ostream& os, const mint& a) { return os << a.x;} struct combination { std::vector<mint> fact, ifact; combination(int n):fact(n+1),ifact(n+1) { assert(n < mod); fact[0] = 1; for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i; ifact[n] = fact[n].inv(); for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i; } mint operator()(int n, int K) { if (K < 0 || K > n) return 0; return fact[n]*ifact[K]*ifact[n-K]; } }; mint solve_slow(ll N,ll M){ mint sum=0; for(ll k=1;k<=N;k++){ sum+=M%k; } return sum; } mint solve2(ll N,ll M){ if(M==1){ return N-1; } mint sum=0; ll l; ll sqrtM=sqrt(M); for(ll d=1;d<=M;d++){ ll r=min(N,M/d); l=M/(d+1); //k=(l,r]の範囲でM-k*dが一定.dはループ変数 if(r==0) break; if(l>r) continue; mint add1=mint( (M-(l+1)*d) + (M-r*d) )*(r-l)/2; cout<<"d="<<d<<",l="<<l<<",r="<<r<<",add1="<<add1<<endl; sum+=add1; } mint add2=0; // for(ll c=1;c<=l;c++){ // add2+=M%c; // } cout<<"sum="<<sum<<endl; cout<<"add2="<<add2<<endl; sum+=add2; return sum; } mint solve(ll N,ll M){ if(M==1){ return N-1; } mint sum=0; ll l,r; ll sqrtM=sqrt(M); for(ll d=0;d<=sqrtM;d++){ r=N; if(d>0){ r=min(N,M/d); } l=M/(d+1); //k=(l,r]の範囲でM-k*dが一定.dはループ変数 if(r==0) break; if(l>r) continue; mint add1=mint( (M-(l+1)*d) + (M-r*d) )*(r-l)/2; //cout<<"d="<<d<<",l="<<l<<",r="<<r<<",add1="<<add1<<endl; sum+=add1; } mint add2=0; for(ll c=1;c<=l;c++){ add2+=M%c; } // cout<<"sum="<<sum<<endl; // cout<<"add2="<<add2<<endl; sum+=add2; return sum; } mt19937_64 engine(1); int main(){ ll N,M; cin>>N>>M; //N=66,M=45; cout<<solve(N,M)<<endl; //cout<<"slow="<<solve_slow(N,M)<<endl; // for(int t=1;t<=100;t++){ // cout<<"t="<<t<<endl; // ll N=engine()%100+1; // ll M=engine()%100+1; // mint ans1=solve(N,M); // mint ans2=solve_slow(N,M); // if(ans1!=ans2){ // cout<<"N="<<N<<",M="<<M<<endl; // cout<<"ans1="<<ans1<<",ans2="<<ans2<<endl; // } // } }