QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#486008 | #4366. Forever Young | ucup-team3474 | TL | 0ms | 3848kb | C++23 | 1.5kb | 2024-07-21 14:26:59 | 2024-07-21 14:26:59 |
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;
}
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
// if(n>=1e6){
// for(int i=y;i<=1000;i++){//ans
// if(gao2(i)){
// cout<<ans<<endl;
// return 0;
// }
// }
// }
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: 3848kb
input:
32 20
output:
16
result:
ok single line: '16'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3648kb
input:
2016 100
output:
42
result:
ok single line: '42'
Test #3:
score: -100
Time Limit Exceeded
input:
1000000000000000000 10