poj 1152

来源:互联网 发布:微信cms系统 编辑:程序博客网 时间:2024/05/16 05:26


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

Submit 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

35A

Sample Output

4611

Source

uva 10093
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
原创粉丝点击