結果

問題 No.2849 Birthday Donuts
ユーザー 👑 kmjpkmjp
提出日時 2024-08-24 00:28:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,063 ms / 6,000 ms
コード長 1,419 bytes
コンパイル時間 2,264 ms
コンパイル使用メモリ 203,324 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-08-24 00:29:42
合計ジャッジ時間 42,240 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
6,812 KB
testcase_01 AC 11 ms
6,940 KB
testcase_02 AC 2,063 ms
6,944 KB
testcase_03 AC 2,046 ms
6,940 KB
testcase_04 AC 1,929 ms
6,940 KB
testcase_05 AC 1,915 ms
6,940 KB
testcase_06 AC 1,932 ms
6,940 KB
testcase_07 AC 1,943 ms
6,940 KB
testcase_08 AC 1,975 ms
6,940 KB
testcase_09 AC 1,941 ms
6,940 KB
testcase_10 AC 1,985 ms
6,940 KB
testcase_11 AC 1,962 ms
6,940 KB
testcase_12 AC 1,784 ms
6,940 KB
testcase_13 AC 1,849 ms
6,940 KB
testcase_14 AC 1,855 ms
6,944 KB
testcase_15 AC 1,838 ms
6,940 KB
testcase_16 AC 1,955 ms
6,940 KB
testcase_17 AC 1,730 ms
6,940 KB
testcase_18 AC 1,922 ms
6,940 KB
testcase_19 AC 1,814 ms
6,940 KB
testcase_20 AC 1,836 ms
6,940 KB
testcase_21 AC 1,634 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

const int MA=202020;
ll tot[MA+1];
ll S[MA+1];
int T;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	for(i=1;i<=MA;i++) tot[i]=i;
	for(i=2;i<=MA;i++) if(tot[i]==i) {
		for(j=i;j<=MA;j+=i) tot[j]=tot[j]/i*(i-1);
	}
	tot[1]=0;
	for(i=1;i<=MA;i++) S[i]=S[i-1]+tot[i];
	
	
	cin>>T;
	ll ret=0;
	while(T--) {
		ll L,R;
		cin>>L>>R;
		L^=ret;
		R^=ret;
		ret=0;
		for(i=1;i<=500;i++) {
			if((L-1)/i!=R/i) ret+=tot[i];
		}
		int pre=500;
		for(i=500;i>=1;i--) {
			int mi=(L+(i-1))/i;
			int ma=R/i;
			if(ma>pre) {
				mi=max(mi,pre+1);
				if(mi<=ma) ret+=S[ma]-S[mi-1];
				pre=ma;
			}
		}
		cout<<ret<<endl;
		
	}
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0