ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#214795 | #2684. Digit Sum | a_sad_soul | 100 | 1157ms | 1264kb | C++11 | 918b | 2024-11-21 21:10:36 | 2024-11-22 09:35:33 |
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll calc(ll x,ll k){
ll re=0;
while(x){
re+=x%k;x/=k;
}
return re;
}
int main(){
int T;scanf("%d",&T);
while(T--){
ll x,n;cin>>x>>n;//swap(n,s);
ll ans=0;
if(x==n){
cout<<(x+1)<<endl;
continue;
}
if(n>x){
puts("-1");
continue;
}
for(ll i=2;i*i<=x;++i)if(calc(x,i)==n){ans=i;break;}
if(ans){
cout<<ans<<endl;
continue;
}
ans=1e18;
for(ll i=1;i*i<=x-n;++i){
if((x-n)%i)continue;
ll an=(x-n)/i;
if(calc(x,an+1)==n)ans=min(ans,an+1);
if(calc(x,i+1)==n)ans=min(ans,i+1);
}
if(ans==1e18){puts("-1");continue;}
printf("%lld\n",ans);
}
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 5
Accepted
time: 0ms
memory: 1232kb
input:
10 888625 163964 35930 5139 531439 147185 749555 345722 69047 16611 55833 9203 307717 106246 933880 ...
output:
724662 30792 192128 403834 26219 9327 201472 -1 -1 -1
result:
ok 10 lines
Test #2:
score: 5
Accepted
time: 1ms
memory: 1232kb
input:
10 450817 145239 822536 101101 234226 52339 995924 105895 378034 2945 639602 284931 147612 44381 253...
output:
152790 144288 60630 127148 6150 354672 103232 -1 -1 574268
result:
ok 10 lines
Test #3:
score: 5
Accepted
time: 1ms
memory: 1228kb
input:
10 23798 4780 503642 62007 363324 80713 37004 7817 540153 82969 199281 32442 520499 159495 447250 37...
output:
9510 88328 282612 9730 114297 55614 180503 -1 -1 -1
result:
ok 10 lines
Test #4:
score: 5
Accepted
time: 1ms
memory: 1228kb
input:
10 537103 140173 203204 73349 296269 133080 483130 200096 305554 36152 209507 29381 957094 13012 740...
output:
198466 129856 163190 283035 38487 30022 17484 -1 -1 -1
result:
ok 10 lines
Test #5:
score: 5
Accepted
time: 0ms
memory: 1228kb
input:
10 87451 9578 905581 255725 521449 257855 748415 342780 5617 1359 452858 52144 822082 373556 389173 ...
output:
77874 324929 263595 405636 2130 200358 448527 -1 -1 -1
result:
ok 10 lines
Test #6:
score: 5
Accepted
time: 0ms
memory: 1232kb
input:
10 947539 24439 567949 142999 783681 16340 770799 241043 997443 117394 907957 61046 76708 8506 42448...
output:
27151 212476 767342 264879 880050 65148 11368 216614 -1 -1
result:
ok 10 lines
Test #7:
score: 5
Accepted
time: 105ms
memory: 1228kb
input:
10 38842382408 122926 58274862930 789360 16726511292 330607 15668542016 1208760580 96592451354 75808...
output:
449762 749131 557336 3614945360 14835268979 4571185507 11244317832 437979598 4591434846 5053027207
result:
ok 10 lines
Test #8:
score: 5
Accepted
time: 82ms
memory: 1260kb
input:
10 73846452295 620455 50989527612 3728 51772807635 209471 41365167624 8035429152 43363365851 9425141...
output:
464265 2747 141180 8332434619 16969112270 2712435470 961081703 13596453717 3076227242 3993912283
result:
ok 10 lines
Test #9:
score: 5
Accepted
time: 82ms
memory: 1260kb
input:
10 22120306776 495832 23247250178 6368 79562554490 19874 32734834718 98896643 35888384281 1089396855...
output:
448097 2296 13849 100418272 12497207863 1183983029 5651041184 884736772 3387552566 7180448987
result:
ok 10 lines
Test #10:
score: 5
Accepted
time: 80ms
memory: 1264kb
input:
10 28130589289 424875 45607070965 465767 66232968981 230686 61515248868 10509226440 11206266868 6337...
output:
483495 362099 183428 12751505608 110325683 8487095258 2016707025 635925380 1150318323 13074499686
result:
ok 10 lines
Test #11:
score: 5
Accepted
time: 79ms
memory: 1260kb
input:
10 15236605640 131590 76773281826 193875 15881927534 233031 67113829687 7741608137 94088859866 21886...
output:
98603 125550 372872 11874444311 220870579 9612998551 3365051413 12240592574 1962947618 14426233068
result:
ok 10 lines
Test #12:
score: 5
Accepted
time: 78ms
memory: 1264kb
input:
10 7747004498 66027 77954096635 182311 72636571992 134139 59371587772 3747319652 31741332987 1562357...
output:
44858 98972 114738 5562426813 1676609756 6458779237 5179405963 12433756531 17875695229 858582085
result:
ok 10 lines
Test #13:
score: 5
Accepted
time: 77ms
memory: 1260kb
input:
10 52447944080 396920 85295225227 490427 16062740018 284170 31819067462 14385061650 73753430383 6315...
output:
231292 347717 221433 17434005813 6743788703 8768103281 4110438251 1133817250 7972670499 455974287
result:
ok 10 lines
Test #14:
score: 5
Accepted
time: 86ms
memory: 1228kb
input:
10 16458964082 785492 39210832198 308576 90579242995 566326 10156100741 1194736390 36992807117 63081...
output:
825966 727388 372460 8961364352 649321355 3655343410 2695511298 4376219037 6927288389 917603750
result:
ok 10 lines
Test #15:
score: 5
Accepted
time: 69ms
memory: 1264kb
input:
10 74391702898 247604 46995162688 153603 30018150177 20343 33463692362 15774161781 33013896733 26419...
output:
209414 97806 16135 17689530582 15185959772 4164863092 440677446 1745706624 2775631956 13925467716
result:
ok 10 lines
Test #16:
score: 5
Accepted
time: 86ms
memory: 1264kb
input:
10 9024265051 320767 44078185701 360375 39291196937 277829 64756922755 6933411003 87474828658 305861...
output:
305597 222523 218015 7227938970 5627747880 1130768501 4579683737 159821876 5619168102 5057422939
result:
ok 10 lines
Test #17:
score: 5
Accepted
time: 78ms
memory: 1264kb
input:
10 11798579336 148692 38029195164 131178 43979560651 741293 63898457237 179757607 92920236151 993757...
output:
77702 74539 873099 202925796 1558075904 2408997891 465505563 2668950213 5667685590 2632204212
result:
ok 10 lines
Test #18:
score: 5
Accepted
time: 91ms
memory: 1260kb
input:
10 26479252755 224121 61958934862 353329 51905628528 766320 75618930758 1077079694 16217470987 11936...
output:
196315 282642 834377 2070606975 1877979509 7449754223 1749669689 15007673886 866170915 753844688
result:
ok 10 lines
Test #19:
score: 5
Accepted
time: 73ms
memory: 1264kb
input:
10 90926376778 796138 73090609979 22899 60520918542 7052 16429107583 16429107583 94872820855 9778764...
output:
695491 20358 3966 16429107584 1159196845 9942680112 6161670822 9009132889 1848542066 4400354549
result:
ok 10 lines
Test #20:
score: 5
Accepted
time: 88ms
memory: 1260kb
input:
10 39325538660 300086 24194702624 301899 59825284594 104522 31201472810 4475319520 50985475546 24450...
output:
205520 232776 71387 5345230659 2554758082 926224335 4804141494 2148216732 4063066102 18557526038
result:
ok 10 lines