ACM Forever Young

author:chenmingdong
Title:
Forever Young
Time limit: 1 second
My birthday is coming up. Alas, I am getting old and would like to feel young again. Fortunately, I have
come up with an excellent way of feeling younger: if I write my age as a number in an appropriately
chosen base b, then it appears to be smaller. For instance, suppose my age in base 10 is 32. Written in
base 16 it is only 20!
However, I cannot choose an arbitrary base when doing this. If my age written in base b contains digits
other than 0 to 9, then it will be obvious that I am cheating, which defeats the purpose. In addition, if
my age written in base b is too small then it would again be obvious that I am cheating.
Given my age y and a lower bound on how small I want my age to appear, find the largest base b such
that y written in base b contains only decimal digits, and is at least
when interpreted as a number in
base 10.
Input
The input consists of a single line containing two base 10 integers y (10 y 1018 – yes, I am very
old) and (10 y).
Output
Display the largest base b as described above.

Sample Input 1 Sample Output 1
32 20 16
Sample Input 2 Sample Output 2
2016 100 42

#include<stdio.h>
int conv(long a,long b)//转化为 b 进制 
{
    if(a==0)
    return true;
    else
    {
        if(a%b>9)//如果余数 大于 9 返回 0 
        return false;
        return conv(a/b,b);//如果所有余数 都小于 9 返回 true 
    }
}
int main()
{
    int i,j,t,temp;
    long real,sum=0;
    char ide[19];
    scanf("%ld",&real);
    scanf("%s",ide);
    for(i=0,t=10;;i++,t++)
    {
        temp =1;
        for(j=1;;j++)
        {
            if(ide[j]==NULL)
            break;
            temp *= t;
        }
        for(j=0;;j++)
        {
            if(ide[j]==NULL)
            break;
            sum += (ide[j] - '0')*temp;
            temp /=t;
        }
        if(sum > real)
        break;
        sum = 0;
    }
    //上面是算出  最大的 基数 t
    //下面是 从 t 开始(t--) 检查 是否符合题意  
    for(i=t;i>9;i--)
    {
        if(conv(real,i)==1)
        break;
    }
    printf("%d",i);
    return 0;
 } 

第一次做这种纯英文题目,大部分时间在理解题意上

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ACM Codebook(ACM代码手册)是一本整理了算法竞赛常用算法和数据结构的参考手册。它是为了帮助算法竞赛选手快速查阅各种算法和数据结构的实现而编写的。 ACM Codebook的内容非常丰富,包括了各种常用算法,如排序算法、图论算法、动态规划算法等。同时,它还包含了各种常用数据结构的实现,如链表、栈、队列、堆等。此外,ACM Codebook还介绍了一些常见的算法设计技巧和优化技巧,帮助选手更好地解决问题。 ACM Codebook的作用非常明显,首先它提供了各种算法和数据结构的实现代码,方便选手直接复制粘贴使用,节省了编写代码的时间。其次,ACM Codebook提供了详细的算法和数据结构的说明和示例,帮助选手理解和掌握这些算法和数据结构的原理和用法。最后,ACM Codebook还提供了一些常见问题的解决方案,帮助选手快速解决问题。 ACM Codebook的编写并不容易,需要作者具备扎实的算法和数据结构基础,并且对算法竞赛有深入的了解。编写ACM Codebook需要不断地修改和更新,以适应算法竞赛中不断变化的需求。 总之,ACM Codebook是一本非常有用的参考手册,它不仅提供了丰富的算法和数据结构的实现,还提供了对应的说明和示例,帮助算法竞赛选手快速掌握和应用这些算法和数据结构。它是算法竞赛选手在比赛中必备的工具之一。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值