ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#214809 | #2684. Digit Sum | erican | 0 | 932ms | 1164kb | C++11 | 1.9kb | 2024-11-21 22:08:07 | 2024-11-22 09:37:11 |
answer
/* Erica N */
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define int long long
#define ull unsigned long long
#define pii pair<int, int>
#define ps second
#define pf first
#define itn int
#define rd read()
int read(){
int xx = 0, ff = 1;char ch = getchar();
while (ch < '0' || ch > '9') {if (ch == '-')ff = -1; ch = getchar();}
while (ch >= '0' && ch <= '9')xx = xx * 10 + (ch - '0'), ch = getchar();
return xx * ff;
}
// void write(int out) {
// if (out < 0)
// putchar('-'), out = -out;
// if (out > 9)
// write(out / 10);
// putchar(out % 10 + '0');
// }
#define cdbg(x...) do { cerr << #x << " -> "; err(x); } while (0)
void err() { cerr << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cerr << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cerr << a << ' '; err(x...); }
const int N = 3e5 + 5;
const int INF = 1e18;
const int M = 1e7;
const int MOD = 1e9 + 7;
inline int get(int a,int p){
int res=0;
while(a){
res+=a%p;
a/=p;
}
return res;
}
bool check(int i,int a,int b){
if((a-b)%i)return 0;
int m=(a-b)/i+1;
if(m<=1)return 0;
int j=b-i;
return i*m+j==a;
}
void solve(){
int a=rd,b=rd;
int B=ceil(sqrt(a));
for(int i=2;i<=B;i++){
// cdbg(a,i,get(a,i));
if(get(a,i)==b){
cout<<i<<endl;
return ;
}
}
for(int i=1;i<=B;i++){
if(check(i,a,b)){
cout<<(a-b)/i+1<<endl;
return ;
}
}
cout<<-1<<endl;
}
signed main() {
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
int T=rd;
while(T--){
solve();
}
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 1164kb
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: 1164kb
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: 0ms
memory: 1164kb
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: 1164kb
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: 1164kb
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: 0ms
memory: 1164kb
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: 83ms
memory: 1156kb
input:
10 38842382408 122926 58274862930 789360 16726511292 330607 15668542016 1208760580 96592451354 75808...
output:
38842259483 58274073571 16726180686 14459781437 89011613869 54854226073 33732953494 32848469776 8723...
result:
wrong answer 1st lines differ - expected: '449762', found: '38842259483'
Test #8:
score: 0
Wrong Answer
time: 64ms
memory: 1164kb
input:
10 73846452295 620455 50989527612 3728 51772807635 209471 41365167624 8035429152 43363365851 9425141...
output:
73845831841 2747 141180 33329738473 33938224539 21699483753 38443268081 40789361149 -1 63902596513
result:
wrong answer 1st lines differ - expected: '464265', found: '73845831841'
Test #9:
score: 0
Wrong Answer
time: 64ms
memory: 1160kb
input:
10 22120306776 495832 23247250178 6368 79562554490 19874 32734834718 98896643 35888384281 1089396855...
output:
22119810945 2296 13849 32635938076 24994415725 93534659213 73463535380 23003156047 67751051301 78984...
result:
wrong answer 1st lines differ - expected: '448097', found: '22119810945'
Test #10:
score: 0
Wrong Answer
time: 68ms
memory: 1160kb
input:
10 28130589289 424875 45607070965 465767 66232968981 230686 61515248868 10509226440 11206266868 6337...
output:
28130164415 45606605199 183428 51006022429 11142893883 59409666800 36300726433 45786627289 483133695...
result:
wrong answer 1st lines differ - expected: '483495', found: '28130164415'
Test #11:
score: 0
Wrong Answer
time: 64ms
memory: 1156kb
input:
10 15236605640 131590 76773281826 193875 15881927534 233031 67113829687 7741608137 94088859866 21886...
output:
98603 125550 15881694504 59372221551 93869995651 48064992751 13460205649 12240592574 88332642766 144...
result:
wrong answer 3rd lines differ - expected: '372872', found: '15881694504'
Test #12:
score: 0
Wrong Answer
time: 62ms
memory: 1160kb
input:
10 7747004498 66027 77954096635 182311 72636571992 134139 59371587772 3747319652 31741332987 1562357...
output:
44858 98972 114738 55624268121 30178975591 19376337709 82870495393 87036295711 53627085685 36060447529
result:
wrong answer 4th lines differ - expected: '5562426813', found: '55624268121'
Test #13:
score: 0
Wrong Answer
time: 62ms
memory: 1164kb
input:
10 52447944080 396920 85295225227 490427 16062740018 284170 31819067462 14385061650 73753430383 6315...
output:
52447547161 85294734801 16062455849 17434005813 67437887021 26304309841 -1 23810162230 15945340997 4...
result:
wrong answer 1st lines differ - expected: '231292', found: '52447547161'
Test #14:
score: 0
Wrong Answer
time: 63ms
memory: 1156kb
input:
10 16458964082 785492 39210832198 308576 90579242995 566326 10156100741 1194736390 36992807117 63081...
output:
16458178591 39210523623 90578676670 8961364352 36361995825 10966030228 24259601674 70019504577 34636...
result:
wrong answer 1st lines differ - expected: '825966', found: '16458178591'
Test #15:
score: 0
Wrong Answer
time: 63ms
memory: 1164kb
input:
10 74391702898 247604 46995162688 153603 30018150177 20343 33463692362 15774161781 33013896733 26419...
output:
209414 97806 16135 17689530582 30371919543 -1 35254195601 73319678167 47185743236 83552806291
result:
wrong answer 5th lines differ - expected: '15185959772', found: '30371919543'
Test #16:
score: 0
Wrong Answer
time: 68ms
memory: 1164kb
input:
10 9024265051 320767 44078185701 360375 39291196937 277829 64756922755 6933411003 87474828658 305861...
output:
9023944285 44077825327 39290919109 57823511753 84416218186 82546100501 54956204833 -1 33715008607 25...
result:
wrong answer 1st lines differ - expected: '305597', found: '9023944285'
Test #17:
score: 0
Wrong Answer
time: 67ms
memory: 1160kb
input:
10 11798579336 148692 38029195164 131178 43979560651 741293 63898457237 179757607 92920236151 993757...
output:
77702 74539 43978819359 63718699631 91926478278 -1 48878084011 56047954453 79347598247 34218654744
result:
wrong answer 3rd lines differ - expected: '873099', found: '43978819359'
Test #18:
score: 0
Wrong Answer
time: 74ms
memory: 1164kb
input:
10 26479252755 224121 61958934862 353329 51905628528 766320 75618930758 1077079694 16217470987 11936...
output:
26479028635 61958581534 51904862209 74541851065 15023836065 67047787999 -1 75038369426 96144971455 2...
result:
wrong answer 1st lines differ - expected: '196315', found: '26479028635'
Test #19:
score: 0
Wrong Answer
time: 60ms
memory: 1164kb
input:
10 90926376778 796138 73090609979 22899 60520918542 7052 16429107583 16429107583 94872820855 9778764...
output:
90925580641 20358 3966 -1 93894944365 9942680112 80101720674 -1 75790224666 4400354549
result:
wrong answer 1st lines differ - expected: '695491', found: '90925580641'
Test #20:
score: 0
Wrong Answer
time: 70ms
memory: 1164kb
input:
10 39325538660 300086 24194702624 301899 59825284594 104522 31201472810 4475319520 50985475546 24450...
output:
39325238575 24194400726 71387 26726153291 48540403540 85212638729 81670405382 75187585586 -1 5567257...
result:
wrong answer 1st lines differ - expected: '205520', found: '39325238575'