关闭

BZOJ 4612([Wf2016]Forever Young-二分)

258人阅读 评论(0) 收藏 举报
分类:

将一个数y转化成b进制数,使得他>=l,且

#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=Pre[x];p;p=Next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=Next[p])  
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,0x3f,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define MEMx(a,b) memset(a,b,sizeof(a));
#define INF (0x3f3f3f3f)
#define F (1000000007)
#define pb push_back
#define mp make_pair 
#define fi first
#define se second
#define vi vector<int> 
#define pi pair<int,int>
#define SI(a) ((a).size())
#define Pr(kcase,ans) printf("Case #%d: %lld\n",kcase,ans);
#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;
#define PRi2D(a,n,m) For(i,n) { \
                        For(j,m-1) cout<<a[i][j]<<' ';\
                        cout<<a[i][m]<<endl; \
                        } 
#pragma comment(linker, "/STACK:102400000,102400000")
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return ((a-b)%F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int read()
{
    int x=0,f=1; char ch=getchar();
    while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
    while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
    return x*f;
} 
ll check(ll m,ll n) {
    return n%10+(n/10%10)*m+(n/100)*m*m;
}
ll l;
bool check2(ll p,ll n) {
    ll t=0,u=1;
    while(n) {
        if (n%p>9) return 0;
        t+=u*(n%p); u*=10;
        n/=p;
    }
    if (t<l) return 0;
    return 1;
}
int main()
{
//  freopen("bzoj4612.in","r",stdin);
//  freopen(".out","w",stdout);
    ll y;
    cin>>y>>l;
    ll an=10;

    for(ll i=l;i<=999;i++) {
        ll L=1,R=1e9,ans=10;
        if (i<100) R=1E18;
        while(L<=R) {
            ll m=(L+R)/2;
            if (check(m,i)<=y) ans=m,L=m+1;
            else R=m-1;  
        }
        if (check(ans ,i)== y )  an=max(an,ans);
    }
    ForD(i,1000000) {
        if (i<an) break;
        if (check2(i,y)) {
            cout<<i<<endl;return 0;
        }
    }
    cout<<an<<endl;
    return 0;
}
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:878340次
    • 积分:18828
    • 等级:
    • 排名:第497名
    • 原创:990篇
    • 转载:16篇
    • 译文:0篇
    • 评论:33条
    博客导航
    文章分类
    最新评论