UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#214782#2684. Digit SumSTASISZHY079ms5944kbC++111.3kb2024-11-21 20:27:132024-11-22 09:34:15

answer

// Problem: C. Digit Sum
// Contest: undefined - NOIP2024训练赛 11
// URL: http://www.noi.ac/contest/1163/problem/2684
// Memory Limit: 1024 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
//#define int long long
#define fi first
#define se second
#define PII pair<int, int>

using namespace std;

const int N = 2e5 + 10, M = 1e6 + 10, mod = 1e9 + 7, INF = 0x3f3f3f3f;

int n, m, q, ans;
int s[N], dp[N];

vector<int> e[N];

inline int work(int x, int op)
{
	int res = 0;
	while(x) res += x % op, x /= op;
	return res;
}

signed main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int T; cin >> T;
	while(T --)
	{
		cin >> n >> m;
		if(n < m) 
		{
			cout << -1 << '\n';
			continue;
		}
		if(m == 1)
		{
			cout << n << '\n';
			continue;
		}
		if(n == m)
		{
			cout << n + 1 << '\n';
			continue;
		}
		int B = sqrt(n), flag = 0;
		for(int i = 2; i <= B; i ++) 
			if(work(n, i) == m) {cout << i << '\n'; flag = 1; break;}
		if(flag) continue;
		int now = n - m;
		for(int i = 1; i <= B; i ++)
		{
			if(now / i < B) break;
			if(now % i == 0) {cout << now / i + 1 << '\n'; flag = 1; break;}
		}
		if(flag) continue;
		cout << -1 << '\n';
	}	
	return 0;
}

详细

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

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 5940kb

input:

10
888625 163964
35930 5139
531439 147185
749555 345722
69047 16611
55833 9203
307717 106246
933880 ...

output:

724662
30792
384255
403834
52437
46631
201472
105772
299031
-1

result:

wrong answer 3rd lines differ - expected: '192128', found: '384255'

Test #2:

score: 0
Wrong Answer
time: 0ms
memory: 5940kb

input:

10
450817 145239
822536 101101
234226 52339
995924 105895
378034 2945
639602 284931
147612 44381
253...

output:

305579
721436
181888
890030
375090
354672
103232
-1
197067
574268

result:

wrong answer 1st lines differ - expected: '152790', found: '305579'

Test #3:

score: 0
Wrong Answer
time: 2ms
memory: 5940kb

input:

10
23798 4780
503642 62007
363324 80713
37004 7817
540153 82969
199281 32442
520499 159495
447250 37...

output:

19019
441636
282612
29188
457185
166840
361005
74983
-1
103234

result:

wrong answer 1st lines differ - expected: '9510', found: '19019'

Test #4:

score: 0
Wrong Answer
time: 0ms
memory: 5940kb

input:

10
537103 140173
203204 73349
296269 133080
483130 200096
305554 36152
209507 29381
957094 13012
740...

output:

396931
129856
163190
283035
269403
180127
944083
219756
-1
-1

result:

wrong answer 1st lines differ - expected: '198466', found: '396931'

Test #5:

score: 0
Wrong Answer
time: 0ms
memory: 5944kb

input:

10
87451 9578
905581 255725
521449 257855
748415 342780
5617 1359
452858 52144
822082 373556
389173 ...

output:

77874
649857
263595
405636
4259
400715
448527
-1
-1
15113

result:

wrong answer 2nd lines differ - expected: '324929', found: '649857'

Test #6:

score: 0
Wrong Answer
time: 4ms
memory: 5940kb

input:

10
947539 24439
567949 142999
783681 16340
770799 241043
997443 117394
907957 61046
76708 8506
42448...

output:

923101
424951
767342
529757
880050
846912
68203
216614
-1
-1

result:

wrong answer 1st lines differ - expected: '27151', found: '923101'

Test #7:

score: 0
Wrong Answer
time: 6ms
memory: 5940kb

input:

10
38842382408 122926
58274862930 789360
16726511292 330607
15668542016 1208760580
96592451354 75808...

output:

-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-214...

result:

wrong answer 1st lines differ - expected: '449762', found: '-2147483648'

Test #8:

score: 0
Wrong Answer
time: 8ms
memory: 5944kb

input:

10
73846452295 620455
50989527612 3728
51772807635 209471
41365167624 8035429152
43363365851 9425141...

output:

-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-214...

result:

wrong answer 1st lines differ - expected: '464265', found: '-2147483648'

Test #9:

score: 0
Wrong Answer
time: 4ms
memory: 5940kb

input:

10
22120306776 495832
23247250178 6368
79562554490 19874
32734834718 98896643
35888384281 1089396855...

output:

-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-214...

result:

wrong answer 1st lines differ - expected: '448097', found: '-2147483648'

Test #10:

score: 0
Wrong Answer
time: 3ms
memory: 5940kb

input:

10
28130589289 424875
45607070965 465767
66232968981 230686
61515248868 10509226440
11206266868 6337...

output:

-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-214...

result:

wrong answer 1st lines differ - expected: '483495', found: '-2147483648'

Test #11:

score: 0
Wrong Answer
time: 4ms
memory: 5944kb

input:

10
15236605640 131590
76773281826 193875
15881927534 233031
67113829687 7741608137
94088859866 21886...

output:

-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-214...

result:

wrong answer 1st lines differ - expected: '98603', found: '-2147483648'

Test #12:

score: 0
Wrong Answer
time: 4ms
memory: 5940kb

input:

10
7747004498 66027
77954096635 182311
72636571992 134139
59371587772 3747319652
31741332987 1562357...

output:

-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-214...

result:

wrong answer 1st lines differ - expected: '44858', found: '-2147483648'

Test #13:

score: 0
Wrong Answer
time: 5ms
memory: 5940kb

input:

10
52447944080 396920
85295225227 490427
16062740018 284170
31819067462 14385061650
73753430383 6315...

output:

-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-214...

result:

wrong answer 1st lines differ - expected: '231292', found: '-2147483648'

Test #14:

score: 0
Wrong Answer
time: 4ms
memory: 5944kb

input:

10
16458964082 785492
39210832198 308576
90579242995 566326
10156100741 1194736390
36992807117 63081...

output:

-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-214...

result:

wrong answer 1st lines differ - expected: '825966', found: '-2147483648'

Test #15:

score: 0
Wrong Answer
time: 4ms
memory: 5940kb

input:

10
74391702898 247604
46995162688 153603
30018150177 20343
33463692362 15774161781
33013896733 26419...

output:

-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-214...

result:

wrong answer 1st lines differ - expected: '209414', found: '-2147483648'

Test #16:

score: 0
Wrong Answer
time: 9ms
memory: 5944kb

input:

10
9024265051 320767
44078185701 360375
39291196937 277829
64756922755 6933411003
87474828658 305861...

output:

-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-214...

result:

wrong answer 1st lines differ - expected: '305597', found: '-2147483648'

Test #17:

score: 0
Wrong Answer
time: 9ms
memory: 5940kb

input:

10
11798579336 148692
38029195164 131178
43979560651 741293
63898457237 179757607
92920236151 993757...

output:

-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-214...

result:

wrong answer 1st lines differ - expected: '77702', found: '-2147483648'

Test #18:

score: 0
Wrong Answer
time: 4ms
memory: 5940kb

input:

10
26479252755 224121
61958934862 353329
51905628528 766320
75618930758 1077079694
16217470987 11936...

output:

-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-214...

result:

wrong answer 1st lines differ - expected: '196315', found: '-2147483648'

Test #19:

score: 0
Wrong Answer
time: 4ms
memory: 5940kb

input:

10
90926376778 796138
73090609979 22899
60520918542 7052
16429107583 16429107583
94872820855 9778764...

output:

-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-214...

result:

wrong answer 1st lines differ - expected: '695491', found: '-2147483648'

Test #20:

score: 0
Wrong Answer
time: 5ms
memory: 5940kb

input:

10
39325538660 300086
24194702624 301899
59825284594 104522
31201472810 4475319520
50985475546 24450...

output:

-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-214...

result:

wrong answer 1st lines differ - expected: '205520', found: '-2147483648'