結果

問題 No.752 mod数列
ユーザー kotatsugamekotatsugame
提出日時 2018-11-10 07:21:25
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 212 ms / 2,000 ms
コード長 552 bytes
コンパイル時間 451 ms
コンパイル使用メモリ 63,876 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-14 10:12:42
合計ジャッジ時間 6,181 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 5 ms
4,380 KB
testcase_11 AC 4 ms
4,376 KB
testcase_12 AC 5 ms
4,376 KB
testcase_13 AC 5 ms
4,380 KB
testcase_14 AC 5 ms
4,380 KB
testcase_15 AC 174 ms
4,376 KB
testcase_16 AC 185 ms
4,376 KB
testcase_17 AC 205 ms
4,376 KB
testcase_18 AC 186 ms
4,376 KB
testcase_19 AC 198 ms
4,380 KB
testcase_20 AC 208 ms
4,380 KB
testcase_21 AC 201 ms
4,380 KB
testcase_22 AC 200 ms
4,380 KB
testcase_23 AC 206 ms
4,376 KB
testcase_24 AC 209 ms
4,380 KB
testcase_25 AC 64 ms
4,376 KB
testcase_26 AC 158 ms
4,380 KB
testcase_27 AC 117 ms
4,376 KB
testcase_28 AC 147 ms
4,376 KB
testcase_29 AC 193 ms
4,380 KB
testcase_30 AC 212 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:17:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   17 | 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);
	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=i==r?r: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