QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#486008#4366. Forever Youngucup-team3474TL 0ms3848kbC++231.5kb2024-07-21 14:26:592024-07-21 14:26:59

Judging History

你现在查看的是最新测评结果

  • [2024-07-21 14:26:59]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3848kb
  • [2024-07-21 14:26:59]
  • 提交

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--;
	}
}

详细

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

output:


result: