結果
| 問題 |
No.752 mod数列
|
| コンテスト | |
| ユーザー |
%20
|
| 提出日時 | 2018-03-08 18:59:35 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 255 ms / 2,000 ms |
| コード長 | 709 bytes |
| コンパイル時間 | 2,082 ms |
| コンパイル使用メモリ | 193,712 KB |
| 最終ジャッジ日時 | 2025-01-05 09:06:03 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 31 |
コンパイルメッセージ
main.cpp:11:1: warning: ISO C++ forbids declaration of ‘main’ with no type [-Wreturn-type]
11 | main(){
| ^~~~
ソースコード
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll tousa(ll a,ll d,ll n){
return n*(2*a+(n-1)*d)/2;
}
ll s[32000],t[32000];
main(){
ll P;
cin>>P;
int sn,tn;
sn=sqrt(P);
tn=P/(sn+1);
for(int i=1;i<=sn;++i){
s[i]=s[i-1]+P%i;
}
for(int i=1;i<=tn;++i){
t[i]=t[i-1]+tousa(P%(P/i),i,P/i-P/(i+1));
}
int Q;
cin>>Q;
for(int i=0;i<Q;++i){
int L,R;
cin>>L>>R;
ll sum;
if(P<L){
sum=tousa(P,0,R-L+1);
}else if(R<=sn){
sum=s[R]-s[L-1];
}else if(sn<L){
sum=tousa(P%L,-P/L,P/(P/L)-L+1);
sum+=t[P/L-1]-t[P/R];
sum+=tousa(P%R,P/R,R-P/(P/R+1));
}else{
sum=s[sn]-s[L-1];
sum+=t[tn]-t[P/R];
sum+=tousa(P%R,P/R,R-P/(P/R+1));
}
cout<<sum<<endl;
}
}
%20