結果

問題 No.752 mod数列
ユーザー %20%20
提出日時 2018-03-08 18:59:35
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 232 ms / 2,000 ms
コード長 709 bytes
コンパイル時間 2,263 ms
コンパイル使用メモリ 196,524 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-15 12:22:54
合計ジャッジ時間 8,429 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 7 ms
5,376 KB
testcase_11 AC 6 ms
5,376 KB
testcase_12 AC 6 ms
5,376 KB
testcase_13 AC 5 ms
5,376 KB
testcase_14 AC 7 ms
5,376 KB
testcase_15 AC 180 ms
5,376 KB
testcase_16 AC 196 ms
5,376 KB
testcase_17 AC 222 ms
5,376 KB
testcase_18 AC 194 ms
5,376 KB
testcase_19 AC 211 ms
5,376 KB
testcase_20 AC 217 ms
5,376 KB
testcase_21 AC 220 ms
5,376 KB
testcase_22 AC 217 ms
5,376 KB
testcase_23 AC 223 ms
5,376 KB
testcase_24 AC 221 ms
5,376 KB
testcase_25 AC 68 ms
5,376 KB
testcase_26 AC 173 ms
5,376 KB
testcase_27 AC 120 ms
5,376 KB
testcase_28 AC 167 ms
5,376 KB
testcase_29 AC 211 ms
5,376 KB
testcase_30 AC 232 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 3 ms
5,376 KB
testcase_33 AC 3 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:11:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   11 | main(){
      | ^~~~

ソースコード

diff #

#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;
	}
}
0