結果
問題 | No.752 mod数列 |
ユーザー |
|
提出日時 | 2018-11-10 07:21:25 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 217 ms / 2,000 ms |
コード長 | 552 bytes |
コンパイル時間 | 747 ms |
コンパイル使用メモリ | 64,256 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-22 06:04:24 |
合計ジャッジ時間 | 6,294 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 31 |
コンパイルメッセージ
main.cpp:17:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 17 | 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); 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=i==r?r: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; } }