結果
| 問題 |
No.752 mod数列
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-11-10 06:57:25 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 552 bytes |
| コンパイル時間 | 593 ms |
| コンパイル使用メモリ | 64,000 KB |
| 実行使用メモリ | 10,624 KB |
| 最終ジャッジ日時 | 2024-11-22 04:50:38 |
| 合計ジャッジ時間 | 54,107 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 14 WA * 2 TLE * 15 |
コンパイルメッセージ
main.cpp:26:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
26 | main()
| ^~~~
ソースコード
#include<iostream>
using namespace std;
long p,q,r;
int sum[1<<17];
long f(int x)
{
long ans=sum[x>r?r:x];
for(int i=1;i<=r;i++)
{
long j=p/i;
long next=p/(i+1);
if(x<=next)continue;
else if(j<=x)
{
ans+=(j-next)*(j-next-1)/2*i+(j-next)*(p%j);
}
else
{
ans+=(j-next)*(j-next-1)/2*i+(j-next)*(p%j);
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=0;i<q;i++)
{
int l,r;cin>>l>>r;
cout<<f(r)-f(l-1)<<endl;
}
}