UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#189488#3373. Recalcitrant1024i1001719ms32360kbC++112.3kb2023-10-04 11:43:442023-10-04 12:27:05

answer

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<complex>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<unordered_map>
#include<list>
#include<set>
#include<queue>
#include<stack>
#define OldTomato ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define fir(i,a,b) for(int i=a;i<=b;++i) 
#define mem(a,x) memset(a,x,sizeof(a))
#define p_ priority_queue
using namespace std;
typedef complex<double> CP;
typedef pair<int,int> PII;
typedef long long ll;
typedef __int128 it;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const ll inf = 1e18;
const int N = 2e5+10;
const int M = 1e6+10;
const int mod = 1e9+7;
const double eps = 1e-6;
inline int lowbit(int x){ return x&(-x);}
using namespace std;
template<typename T>void write(T x)
{
	if(x<0)
	{
		putchar('-');
		x=-x;
	}
	if(x>9)
	{
		write(x/10);
	}
	putchar(x%10+'0');
}
template<typename T> void read(T &x)
{
	x = 0;char ch = getchar();ll f = 1;
	while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
	while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}
#define int __int128
int n,m,k,T;
int l,r;
int f1(int n) 
{
	return n*(n+1)*(2*n+1)/6;
}
int f2(int n)
{
	return n*(n+1)/2;
}
int qpow(int a,int k)
{
	int res = 1;
	while(k)
	{
		if(k&1) res = res * a ;
		a = a * a;
		k >>= 1;
	}
	return res;
}
int a[M];
int s[M];
void solve()
{
	read(l); read(r);
	read(k);
	if(k!=1) l -- ;
	int ans = 0;
	if(k == 1)
	{
		ans += (r-l+1) * (l+r)/2;
	}
	else if(k == 2) 
	{
		int idx1 = sqrt((ll)l);
		int idx2 = sqrt((ll)r);
		int res1 = 2 * f1(idx1-1) + f2(idx1-1);
		int res2 = 2 * f1(idx2-1) + f2(idx2-1);
		res1 += (l - qpow(idx1,k) + 1) * (idx1);
		res2 += (r - qpow(idx2,k) + 1) * (idx2);
		ans = res2 - res1;
	}
	else 
	{
		int i = 1;
		for(i=1;;++i)
		{
			a[i] = qpow(i,k);
			if(a[i] > r) break;
			s[i] = s[i-1] + (a[i] - a[i-1]) * (i-1) + 1;
		}
		n = i-1;
		int idx1 = lower_bound(a+1,a+n+1,l) - a;
		idx1 -- ;
		int idx2 = lower_bound(a+1,a+n+1,r) - a;
		idx2 -- ;
		int res1 = s[idx1];
		int res2 = s[idx2];
		res1 += (l - a[idx1]) * (idx1);
		res2 += (r - a[idx2]) * (idx2);
		ans = res2 - res1;
	}
	write(ans);
	cout<<"\n";
}
signed main(void)
{  
	read(T);
	while(T--)
	{
		solve();
	}
	return 0;
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 5
Accepted
time: 0ms
memory: 1148kb

input:

100
15118 84235 1
32372 88962 2
16768 85884 3
18185 94916 1
18166 83452 2
8733 81664 3
34436 85284 1...

output:

3433540327
13778567
2485265
4339232966
14407111
2486119
3043821140
9544314
3072741
3621823395
122993...

result:

ok 100 lines

Test #2:

score: 5
Accepted
time: 0ms
memory: 1144kb

input:

100
8955 54830 1
38604 77553 2
2258 54027 3
7714 61604 1
31169 76246 2
7784 70826 3
2503 87095 1
134...

output:

1463100330
9322375
1483754
1867808169
10344878
2050790
3789681807
11682335
1087051
4210351215
906797...

result:

ok 100 lines

Test #3:

score: 5
Accepted
time: 0ms
memory: 1176kb

input:

100
140475747 856681707 1
141833908 531141172 2
274734376 840618654 3
230182185 643617672 1
17671693...

output:

357085056305191647
7034330567510
460779578674
180629935146562608
15625286914868
399061007686
2868509...

result:

ok 100 lines

Test #4:

score: 5
Accepted
time: 0ms
memory: 1176kb

input:

100
161769818 773482522 1
343946418 737282731 2
46145439 727086747 3
255092487 622073062 1
217452437...

output:

286052869379489850
9093565189919
477599692911
160951359209688112
13479892536541
551084557655
3556510...

result:

ok 100 lines

Test #5:

score: 5
Accepted
time: 0ms
memory: 1172kb

input:

100
197889136 803337038 1
185577491 987484674 2
237976065 646785050 3
446826604 898549816 1
29316005...

output:

303095143738506561
19001546128993
308700129529
303868879568418730
8808769272807
447917224215
1628519...

result:

ok 100 lines

Test #6:

score: 5
Accepted
time: 0ms
memory: 1176kb

input:

100
129867153 892617967 1
148525201 725890573 2
72195289 618180287 3
254594024 618977863 1
95534736 ...

output:

389950679302686400
11831119588236
372136217884
159157739350553040
8597802868983
556540630556
4393852...

result:

ok 100 lines

Test #7:

score: 5
Accepted
time: 0ms
memory: 1172kb

input:

100
66995350 537696026 1
136817913 810913659 2
10303493 974780478 3
333642651 807830349 1
119265180 ...

output:

142314320029630776
14327444241622
722723421821
270636227670313500
14133740402616
439505493031
261051...

result:

ok 100 lines

Test #8:

score: 5
Accepted
time: 0ms
memory: 1180kb

input:

100
235460639 635173120 1
137349407 654307205 2
223175157 670816547 3
225956099 909634120 1
70016560...

output:

174001590361439919
10084489920331
338666706099
388189037364233409
19356227303450
414058864893
485885...

result:

ok 100 lines

Test #9:

score: 5
Accepted
time: 1ms
memory: 1136kb

input:

100
139945333395875355 888132507315968292 1
22862668516058540 611266612371164631 1
64070078576492113...

output:

384597327106032883410098081782432443
186562084894022231669803475742828866
23716016624259675122549180...

result:

ok 100 lines

Test #10:

score: 5
Accepted
time: 0ms
memory: 1140kb

input:

100
259495222615998010 882381636180533506 1
365827115207535585 753429140411090141 1
1489736610389034...

output:

355629790654054516418095424630611726
216912995699763335198311635302366691
17521108602803202137585965...

result:

ok 100 lines

Test #11:

score: 5
Accepted
time: 163ms
memory: 31904kb

input:

100
47476887889946414 907429828998266227 1
220628448899110465 536076455614126515 2
21193286565907010...

output:

410587419836054073411004516532784387
192579187569768899257652032
369621751197030796954375
2416692586...

result:

ok 100 lines

Test #12:

score: 5
Accepted
time: 165ms
memory: 32360kb

input:

100
34454220751729976 672749616295136699 1
69429165308236678 594794677185351000 2
285198277019438911...

output:

225702476448822359060664639663261350
293619280293952636264359537
469683630018078996141526
2616602734...

result:

ok 100 lines

Test #13:

score: 5
Accepted
time: 167ms
memory: 32032kb

input:

100
385670972434896958 790897522596544204 1
290174621906589089 883494833833276163 2
2224610287085865...

output:

238388396135236050867008371139890507
449416575914442930852496245
247604904037928363836218
1461524090...

result:

ok 100 lines

Test #14:

score: 5
Accepted
time: 170ms
memory: 32184kb

input:

100
106618069024882897 506810317952894219 1
184436736173405953 820122985249452600 2
2920161940418947...

output:

122744642870459519529999840509142234
442333504574102107620010114
467544028352537909382555
3548322751...

result:

ok 100 lines

Test #15:

score: 5
Accepted
time: 177ms
memory: 32196kb

input:

100
5298350080805128 668001344213743873 1
103955296302884616 612025375684830066 2
74359476762249961 ...

output:

223098861678894978942054846414246373
296855088022068759623294367
318491496344128799783461
2989158410...

result:

ok 100 lines

Test #16:

score: 5
Accepted
time: 188ms
memory: 32056kb

input:

100
228015815435806080 633800757329584008 1
15690607315665922 509481026229188122 2
11307953901147982...

output:

174856093951349327642596481864883876
241127746370768021641521339
494383153071285583330299
4003862634...

result:

ok 100 lines

Test #17:

score: 5
Accepted
time: 168ms
memory: 32308kb

input:

100
54779617174803827 854011921101683412 1
285175311662706126 825325861336606756 2
7517395738671102 ...

output:

363167777462984935767047531309301527
398332467035583179438265973
377204513673451699332867
1226038386...

result:

ok 100 lines

Test #18:

score: 5
Accepted
time: 183ms
memory: 31956kb

input:

100
21368354243253825 790458741215427997 1
109263445925818655 643464044388985408 2
14468556553962636...

output:

312184207500406892339849673986491603
320030277907290946106205829
462195830417667466181044
1795805937...

result:

ok 100 lines

Test #19:

score: 5
Accepted
time: 172ms
memory: 32248kb

input:

100
145710077422188054 838045140591449599 1
107756513391460322 509254184433097613 2
9126307498982102...

output:

340544115503281244217741248615295769
218694500554653821196653674
579766049352306362834500
1415754940...

result:

ok 100 lines

Test #20:

score: 5
Accepted
time: 165ms
memory: 32260kb

input:

100
354119804395075091 752661612487477770 1
201507804004831287 532819181135933686 2
2599678172110634...

output:

220549333523721954986328908799033740
198981611799282702473943838
250788380808084147589908
1589348328...

result:

ok 100 lines

Extra Test:

score: 0
Extra Test Passed