結果

問題 No.752 mod数列
ユーザー chocoruskchocorusk
提出日時 2018-11-10 09:26:37
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 212 ms / 2,000 ms
コード長 916 bytes
コンパイル時間 2,190 ms
コンパイル使用メモリ 93,844 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-14 14:22:16
合計ジャッジ時間 8,669 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 4 ms
4,380 KB
testcase_11 AC 5 ms
4,380 KB
testcase_12 AC 5 ms
4,376 KB
testcase_13 AC 5 ms
4,380 KB
testcase_14 AC 4 ms
4,376 KB
testcase_15 AC 179 ms
4,380 KB
testcase_16 AC 194 ms
4,380 KB
testcase_17 AC 212 ms
4,384 KB
testcase_18 AC 191 ms
4,380 KB
testcase_19 AC 209 ms
4,376 KB
testcase_20 AC 191 ms
4,376 KB
testcase_21 AC 208 ms
4,380 KB
testcase_22 AC 212 ms
4,380 KB
testcase_23 AC 198 ms
4,380 KB
testcase_24 AC 188 ms
4,376 KB
testcase_25 AC 55 ms
4,380 KB
testcase_26 AC 145 ms
4,376 KB
testcase_27 AC 102 ms
4,376 KB
testcase_28 AC 136 ms
4,376 KB
testcase_29 AC 176 ms
4,376 KB
testcase_30 AC 201 ms
4,376 KB
testcase_31 AC 1 ms
4,384 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 2 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
ll p, m;
ll ss[33000];
ll sl[33000];
ll solve(ll x){
	if(x==0) return 0;
	if(x<=p/(m+1)) return ss[x];
	ll ans=ss[p/(m+1)];
	ll k=p/x;
	ans+=sl[k+1];
	ans+=(p*x-k*x*(x+1)/2);
	ans-=(p*(p/(k+1))-k*(p/(k+1))*(p/(k+1)+1)/2);
	return ans;
}
int main()
{
	cin>>p;
	m=(ll)sqrt((double)p);
	for(ll i=1; i<=p/(m+1); i++){
		ss[i]=ss[i-1]+(p%i);
	}
	for(ll i=m; i>=1; i--){
		ll s=p*(p/i-p/(i+1))-i*(p/i)*(p/i+1)/2+i*(p/(i+1))*(p/(i+1)+1)/2;
		sl[i]=sl[i+1]+s;
	}
	int q; cin>>q;
	for(int i=0; i<q; i++){
		ll l, r; cin>>l>>r;
		cout<<solve(r)-solve(l-1)<<endl;
	}
	return 0;
}
0