QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#372900 | #4366. Forever Young | InfinityNS# | WA | 3ms | 4060kb | C++14 | 1.4kb | 2024-03-31 20:31:01 | 2024-03-31 20:31:04 |
Judging History
answer
#include<bits/stdc++.h>
#define f first
#define s second
#define ll long long
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) x.begin(),x.end()
using namespace std;
int main(){
ll y,l;
scanf("%lld %lld",&y,&l);
for(ll ans=l;ans<1000;ans++){
vector<int> digs;
ll tr=ans;
while(tr){
digs.pb(tr%10);
tr/=10;
}
ll lb=11,rb=y;
ll res=-1;
while(lb<=rb){
ll md=(lb+rb)/2;
__int128 anss=0,tr=1;
for(auto p:digs){
if(tr>y){
anss=-1;
break;
}
anss+=tr*p;
tr*=md;
}
if(anss>y){
rb=md-1;
}
else{
if(anss==y)res=md;
lb=md+1;
}
}
if(res!=-1){
printf("%lld\n",res);
return 0;
}
}
for(int base=1e6;base>=10;base--){
bool ok=1;
__int128 ans=0,trs=1;
ll tr=y;
while(tr){
ll dig=tr%base;
tr/=base;
if(dig>=10){
ok=0;break;
}
ans+=dig*trs;
trs*=10;
}
if(ok&&ans>=l){
printf("%i\n",base);
return 0;
}
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3740kb
input:
32 20
output:
16
result:
ok single line: '16'
Test #2:
score: 0
Accepted
time: 2ms
memory: 4060kb
input:
2016 100
output:
42
result:
ok single line: '42'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3764kb
input:
1000000000000000000 10
output:
1000000000000000000
result:
ok single line: '1000000000000000000'
Test #4:
score: 0
Accepted
time: 3ms
memory: 4016kb
input:
149239876439186 470
output:
11
result:
ok single line: '11'
Test #5:
score: 0
Accepted
time: 0ms
memory: 4020kb
input:
4851495 95
output:
539054
result:
ok single line: '539054'
Test #6:
score: 0
Accepted
time: 3ms
memory: 3780kb
input:
19839853985 19839853985
output:
10
result:
ok single line: '10'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3720kb
input:
1000000000000000000 17
output:
999999999999999993
result:
ok single line: '999999999999999993'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3776kb
input:
1000000000000000000 23
output:
499999999999999998
result:
ok single line: '499999999999999998'
Test #9:
score: 0
Accepted
time: 1ms
memory: 3724kb
input:
1000000000000000000 58
output:
166666666666666666
result:
ok single line: '166666666666666666'
Test #10:
score: -100
Wrong Answer
time: 1ms
memory: 4020kb
input:
1000000000000000000 145
output:
1000000
result:
wrong answer 1st lines differ - expected: '999999997', found: '1000000'