UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#214787#2835. 机器故障探测a_sad_soul02ms1208kbC++11601b2024-11-21 20:42:002024-11-22 09:34: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;
        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;
        }
    }
    return 0;
}

详细

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

Test #1:

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

input:

6 2

output:

-1
-1
-1
-1
-1
-1

result:

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

Test #2:

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

input:

7 4

output:

-1
-1
-1
-1
-1
-1
-1

result:

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

Test #3:

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

input:

8 2

output:

-1
-1
-1
-1
-1
-1
-1
-1

result:

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

Test #4:

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

input:

50 5

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-...

result:

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

Test #5:

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

input:

49 3

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-...

result:

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

Test #6:

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

input:

45 45

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-...

result:

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

Test #7:

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

input:

44 1

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-...

result:

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

Test #8:

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

input:

498 1

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-...

result:

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

Test #9:

score: 0
Wrong Answer
time: 1ms
memory: 1208kb

input:

300 10

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-...

result:

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

Test #10:

score: 0
Wrong Answer
time: 1ms
memory: 1208kb

input:

500 23

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-...

result:

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