結果

問題 No.752 mod数列
ユーザー kotatsugamekotatsugame
提出日時 2018-11-10 07:08:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 566 bytes
コンパイル時間 566 ms
コンパイル使用メモリ 64,000 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-01 22:21:03
合計ジャッジ時間 6,141 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 WA -
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 3 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 WA -
testcase_11 AC 4 ms
5,376 KB
testcase_12 AC 5 ms
5,376 KB
testcase_13 AC 5 ms
5,376 KB
testcase_14 AC 6 ms
5,376 KB
testcase_15 AC 177 ms
5,376 KB
testcase_16 WA -
testcase_17 AC 220 ms
5,376 KB
testcase_18 AC 194 ms
5,376 KB
testcase_19 AC 207 ms
5,376 KB
testcase_20 AC 222 ms
5,376 KB
testcase_21 AC 223 ms
5,376 KB
testcase_22 AC 219 ms
5,376 KB
testcase_23 AC 221 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 WA -
testcase_28 WA -
testcase_29 AC 210 ms
5,376 KB
testcase_30 AC 229 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 3 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:18:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   18 | main()
      | ^~~~

ソースコード

diff #

#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);
	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=r;i>0;i--)
	{
		long j=p/i;
		long next=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;
	}
}
0