UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#166796#2909. numberLJ071002567ms3004kbC++111.2kb2022-11-22 20:06:212022-11-22 20:06:23

answer

#include<bits/stdc++.h>
using namespace std;
char Ic[1000000],*Is,*It;
#define getchar() ((Is==It)&&(It=Ic+fread(Is=Ic,1,1000000,stdin)),Is==It?EOF:*Is++)
int q,s[100005],ps;
long long f[15][95][105],pw[15]{1},x,y,tx;
long long rd(){char c;while(!isdigit(c=getchar()));long long x(c-48);while(isdigit(c=getchar()))x=x*10+c-48;return x;}
void pt(long long x){int st[20],tp(0);do st[++tp]=x%10;while(x/=10);do putchar(st[tp--]+48);while(tp);puts("");}
int F(long long x)
{
	return s[x/100000]+s[x%100000];
}
void prepare()
{
	for(int i(1);i<100000;++i)s[i]=s[i/10]+(i%10);
	for(int i(1);i<=10;++i)pw[i]=pw[i-1]*10;
	for(int i(0);i<10;++i)
		for(int j(0);j<=9*(10-i);++j)
			for(int z(0);z<100;++z)
			{
				if(!i)f[i][j][z]=j;
				else if(j||z)
				{
					long long t(z);
					while(t<pw[i])t+=f[i-1][j+t/pw[i-1]][t%pw[i-1]];
					f[i][j][z]=t-z;
				}
			}
}
int main()
{
	for(prepare(),scanf("%d",&q);q--;)
	{
		for(x=rd(),y=rd(),ps=tx=0;ps<10&&tx<=y;++ps)
		{
			do
			{
				tx=x+f[ps][F(x/pw[ps])][x%pw[ps]];
				if(tx>y)break;x=tx;
			}while(x/pw[ps]%10);
		}
		while(ps--)
		{
			for(;;)	
			{
				tx=x+f[ps][F(x/pw[ps])][x%pw[ps]];
				if(tx>y)break;x=tx;
			}
		}
		pt(x+F(x));
	}
	return 0;
}

Details

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

Subtask #1:

score: 20
Accepted

Test #1:

score: 20
Accepted
time: 348ms
memory: 3000kb

input:

500000
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 ...

output:

2
4
4
8
8
8
8
16
16
16
16
16
16
16
16
23
23
23
23
23
23
23
28
28
28
28
28
38
38
38
38
38
38
38
38
38...

result:

ok 500000 lines

Test #2:

score: 0
Accepted
time: 881ms
memory: 3004kb

input:

500000
92 99927
119 99453
481 99268
29 99908
267 99547
835 99500
955 99099
734 99774
306 99883
729 9...

output:

99941
99454
99274
99941
99555
99520
99112
99775
99900
99657
99978
100010
99545
99245
99775
99907
997...

result:

ok 500000 lines

Subtask #2:

score: 25
Accepted

Test #3:

score: 25
Accepted
time: 482ms
memory: 3004kb

input:

500000
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 ...

output:

2
4
4
8
8
8
8
16
16
16
16
16
16
16
16
23
23
23
23
23
23
23
28
28
28
28
28
38
38
38
38
38
38
38
38
38...

result:

ok 500000 lines

Subtask #3:

score: 25
Accepted

Test #4:

score: 25
Accepted
time: 6ms
memory: 2020kb

input:

50
4587480273 4587480273
428862505 500400481
6920415626 7358620174
7787875953 7787884613
4542304779 ...

output:

4587480321
500400482
7358620210
7787884620
4542307848
4676070172
909798356
3555627285
9508855574
511...

result:

ok 50 lines

Subtask #4:

score: 30
Accepted

Test #5:

score: 30
Accepted
time: 850ms
memory: 3004kb

input:

500000
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 ...

output:

2
4
4
8
8
8
8
16
16
16
16
16
16
16
16
23
23
23
23
23
23
23
28
28
28
28
28
38
38
38
38
38
38
38
38
38...

result:

ok 500000 lines