結果
| 問題 | No.752 mod数列 |
| コンテスト | |
| ユーザー |
%20
|
| 提出日時 | 2018-03-09 01:01:35 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 23 ms / 2,000 ms |
| コード長 | 742 bytes |
| 記録 | |
| コンパイル時間 | 1,285 ms |
| コンパイル使用メモリ | 209,708 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-06-06 22:23:21 |
| 合計ジャッジ時間 | 3,555 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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;
scanf("%lld",&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;
scanf("%d",&Q);
for(int i=0;i<Q;++i){
int L,R;
scanf("%d%d",&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));
}
printf("%lld\n",sum);
}
}
%20