結果
問題 |
No.752 mod数列
|
ユーザー |
|
提出日時 | 2018-11-10 07:08:01 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 566 bytes |
コンパイル時間 | 952 ms |
コンパイル使用メモリ | 64,000 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-22 05:33:13 |
合計ジャッジ時間 | 5,997 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 WA * 5 |
コンパイルメッセージ
main.cpp:18:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 18 | main() | ^~~~
ソースコード
#include<iostream> using namespace std; long p,q,r; long sum[1<<17]; long cnt[1<<17]; long f(int x) { long ans=sum[x>r?r:x]; if(x<=r)return ans; if(x>=p)return ans+cnt[1]+(x-p)*p; int i=(p-1)/x; long j=p/i; ans+=cnt[i]; ans-=(j-x)*(j-x-1)/2*i+(j-x)*(p%j); if(x>p)ans+=(x-p)*p; return ans; } main() { cin>>p>>q; for(int i=1;i*i<=p;r=i++)sum[i]=sum[i-1]+p%i; for(int i=r;i>0;i--) { long j=p/i; long next=p/(i+1); cnt[i]=(j-next)*(j-next-1)/2*i+(j-next)*(p%j)+cnt[i+1]; } for(int i=0;i<q;i++) { int l,r;cin>>l>>r; cout<<f(r)-f(l-1)<<endl; } }