UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#193734#3404. 挑战数学题Tom6661005398ms1196kbC++11639b2023-10-14 11:41:582023-10-14 13:10:41

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e6 + 10, mod = 1e9 + 7; 
int n, t, a, b, res, m, k;
main() {
	for (scanf("%lld", &t); t; t -- ) {
		scanf("%lld%lld%lld%lld%lld", &n, &k, &m, &a, &b);
		if (k == 1) {
			if (n % m) printf("-1\n");
			else printf("0\n");
			continue;
		}
		res = 2e18;
		for (int i = 0; ~i; n /= k, i ++ ) {
			if (n == 0) {
				res = min(res, i * b);
				break;
			}
			__int128 l = n, r = n;
			int ans = i * b;
			while (l / m == r / m && l % m)
				l *= k, r = r * k + k - 1, ans += a;
			res = min(res, ans);
		}
		printf("%lld\n", res);
	}
}

详细

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

Test #1:

score: 10
Accepted
time: 0ms
memory: 1196kb

input:

1000
8 2 2 59003 81867
3 2 2 89039 80745
1 2 2 53711 65018
2 2 2 32715 17151
10 2 2 84528 34886
8 2 ...

output:

0
89039
53711
0
0
0
0
42487
0
0
50912
12681
28375
34729
5490
0
0
51761
0
0
0
0
37779
0
0
35976
0
0
0...

result:

ok 1000 lines

Test #2:

score: 10
Accepted
time: 0ms
memory: 1192kb

input:

1000
2 2 2 37780 86555
7 2 2 89129 7178
2 2 2 17951 52958
10 2 2 26936 42012
3 2 2 60665 93891
6 2 2...

output:

0
21534
0
0
60665
0
58576
2679
2832
0
0
0
0
0
43604
0
0
0
33080
2323
0
8002
0
34150
0
0
1511
29519
3...

result:

ok 1000 lines

Test #3:

score: 10
Accepted
time: 0ms
memory: 1196kb

input:

1000
10 2 2 8045 50026
9 2 2 89220 76715
9 2 2 90704 49411
6 2 2 21157 99577
9 2 2 4097 95999
6 2 2 ...

output:

0
76715
49411
0
4097
0
0
0
17641
16686
27772
2329
67893
0
6300
0
0
0
34980
0
0
0
0
9665
0
0
0
8626
3...

result:

ok 1000 lines

Test #4:

score: 10
Accepted
time: 0ms
memory: 1196kb

input:

1000
3118508115828426 154 868 8132 41884
3931579548240732 941 701 74555 47816
8449377952493847 2 884...

output:

16264
74555
200925
20082
95409
86422
78597
103612
36637
54923
57113
86840
5583
13436
86568
35561
158...

result:

ok 1000 lines

Test #5:

score: 10
Accepted
time: 1ms
memory: 1192kb

input:

1000
3944755588879146 303 819 86909 13867
8763291186392016 129 516 74646 74250
1625936469431466 89 4...

output:

86909
74646
38540
33473
6137
5046
37433
11998
27254
101016
191086
68466
52106
45826
56655
30096
4966...

result:

ok 1000 lines

Test #6:

score: 10
Accepted
time: 0ms
memory: 1196kb

input:

1000
4770994471995274 968 769 65686 10042
3594998529576004 877 457 74736 43787
1430449541658685 176 ...

output:

60252
74736
83510
27694
192224
10112
61677
37598
37436
8312
33973
31002
65925
84934
139692
19224
285...

result:

ok 1000 lines

Test #7:

score: 10
Accepted
time: 100ms
memory: 1196kb

input:

100000
757248424647325 9288055 3367590 725196382 731761592
6919961090641335 53803149 9360478 9641988...

output:

725196382
964198834
1443265902
582242864
963073930
822181745
11039167
506248991
786652862
42778830
2...

result:

ok 100000 lines

Test #8:

score: 10
Accepted
time: 85ms
memory: 1196kb

input:

100000
1583487307763453 50158960 46751588 269675159 461533575
1751668433825323 6733605 70973366 5174...

output:

269675159
103484058
1164455072
295337086
330050067
433397845
103330707
294241887
816252078
170100802...

result:

ok 100000 lines

Test #9:

score: 10
Accepted
time: 2366ms
memory: 1192kb

input:

100000
4716583217277151 4 52747498 12693575 899798681
829175712575305 2 44541602 440174460 495757286...

output:

165016475
11444535960
1730329699
2217034737
1941792230
674845276
6456301760
3564603108
1132871139
84...

result:

ok 100000 lines

Test #10:

score: 10
Accepted
time: 2846ms
memory: 1192kb

input:

100000
3484326877769848 5 1259851 527002834 883146585
5159038285612059 4 6611676 5765801 40208038
59...

output:

3689019838
63423811
12060546023
9233251907
2559958074
6814788860
2053302691
979027344
6094806841
273...

result:

ok 100000 lines

Extra Test:

score: 0
Extra Test Passed