QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#486009 | #4366. Forever Young | ucup-team3474 | TL | 1ms | 3788kb | C++23 | 1.8kb | 2024-07-21 14:27:20 | 2024-07-21 14:27:21 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N=1919810;
typedef long long ll;
typedef pair<ll,ll> PII;
ll n,y,b,d;
ll ans;
bool cal(vector<ll> &a,double jz){
double sum=0,item=1;
for(int i=0;i<a.size();i++){
sum+=a[i]*item;
if(sum>n) return true;
item*=jz;
}
return sum>n;
}
double gao1(){
vector<ll> v;
ll yy=y;
while(yy){
v.push_back(yy%10);
yy/=10;
}
double l=0,r=1e18;
for(int i=0;i<200;i++){
double mid=(l+r)/2;
if(cal(v,mid)) r=mid;
else l=mid;
}
return l;
}
bool gao2(ll x){
vector<ll> v;
ll xx=x;
while(xx){
v.push_back(xx%10);
xx/=10;
}
ll l=0,r=1e18;
while(l<r){
ll mid=(l+r)/2;
if(cal(v,mid)) r=mid;
else l=mid+1;
}
ll sum=0,item=1;
for(int i=0;i<v.size();i++){
sum+=v[i]*item;
item*=l;
}
if(n==sum){
ans=l;
return true;
}
l++;
sum=0,item=1;
for(int i=0;i<v.size();i++){
sum+=v[i]*item;
item*=l;
}
if(n==sum){
ans=l;
return true;
}
l-=2;
sum=0,item=1;
for(int i=0;i<v.size();i++){
sum+=v[i]*item;
item*=l;
}
if(n==sum){
ans=l;
return true;
}
return false;
}
bool gao3(ll x){
ll nn=n;
while(nn){
if(nn%x>=10) return false;
nn/=x;
}
return true;
}
int main() {
cin>>n>>y;
b=ceil(gao1());//jz
for(int i=y;i<=1000&&i<=n;i++){//ans
if(gao2(i)){
cout<<ans<<endl;
return 0;
}
}
if(b>=1e5) b=1e5;
while(b>10){
if(gao3(b)){
cout<<b<<endl;
return 0;
}
b--;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3652kb
input:
32 20
output:
16
result:
ok single line: '16'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3788kb
input:
2016 100
output:
42
result:
ok single line: '42'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
1000000000000000000 10
output:
1000000000000000000
result:
ok single line: '1000000000000000000'
Test #4:
score: 0
Accepted
time: 1ms
memory: 3788kb
input:
149239876439186 470
output:
11
result:
ok single line: '11'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
4851495 95
output:
539054
result:
ok single line: '539054'
Test #6:
score: -100
Time Limit Exceeded
input:
19839853985 19839853985