poj 1152


Time Limit: 1000MS Memory Limit: 10000KB 64bit IO Format: %lld & %llu

 Status

Description

Have you heard the fact "The base of every normal number system is 10" ? Of course, I am not talking about number systems like Stern Brockot Number System. This problem has nothing to do with this fact but may have some similarity. 

You will be given an N based integer number R and you are given the guaranty that R is divisible by (N-1). You will have to print the smallest possible value for N. The range for N is 2 <= N <= 62 and the digit symbols for 62 based number is (0..9 and A..Z and a..z). Similarly, the digit symbols for 61 based number system is (0..9 and A..Z and a..y) and so on.

Input

Each line in the input will contain an integer (as defined in mathematics) number of any integer base (2..62). You will have to determine what is the smallest possible base of that number for the given conditions. No invalid number will be given as input. The largest size of the input file will be 32KB.

Output

If number with such condition is not possible output the line "such number is impossible!" For each line of input there will be only a single line of output. The output will always be in decimal number system.

Sample Input

3
5
A

Sample Output

4
6
11

Source

Problem descriptions:
System Crawler 2016-08-09
Initialization.


/*
http://acm.pku.edu.cn/JudgeOnline/problem?id=1152
数论知识
给定一个N进制数R(ri, ri-1, ri-1, ... , r2, r1, r0)
则 R = ri * (N ^ i) + ri-1 * (N ^ i-1) + ri-2 * (N ^ i - 2) + ... + r2 * (N ^ 2) + r1 * (N ^ 1) + r0 * (N ^ 0)
     = ri * {[(N - 1) + 1] ^ i} + ri-1 * {[(N - 1) + 1] ^ i-1} + ri-2 * {[(N - 1) + 1] ^ i - 2} + ... + r2 * {[(N - 1) + 1] * ^ 2} + r1 * {[(N - 1) + 1] ^ 1} + r0 * {[(N - 1) + 1] ^ 0}
所以 R mod (N - 1) = (ri + ri-1 + ri-2 + ... + r2 + r1 + r0) mod (N - 1)
so, the rest of the work is really easy...
不过要注意输入为单个0的情况,由于N必须>=2, 所以0应该输出2                
*/


#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
using namespace std;


int main()
{
    string str;
    while(cin>>str)
    {
        int sum=0, num=-1, len=str.size();
        for(int i=0;i<len;i++)
        {
            int cnt;
            if(str[i]>='0'&&str[i]<='9')
            {
                cnt=(str[i]-'0');
            }
            else if(str[i]>='a'&&str[i]<='z')
            {
                cnt=(str[i]-'a')+36;
            }
            else
            {
                cnt=(str[i]-'A')+10;
            }
            sum+=cnt;
            num=max(num,cnt);
        }
        int i;
        for(i=num;i<=61;i++)
        {
            if(sum%i==0)
            {
                printf("%d\n",i+1);
                break;
            }
        }
        if(i>=62)
        {
            printf("such number is impossible!\n");
        }
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值