poj——1152——An Easy Problem!

来源:互联网 发布:网络毛笔字 编辑:程序博客网 时间:2024/05/21 08:47

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

#include<iostream>#include<stdio.h>#include<string.h>using namespace std;char a[100000];int main(){    int i,s,len,max;    bool d;    while(scanf("%s",a)!=EOF)    {        len=strlen(a);        s=0;        max=0;        for(i=0;i<len;i++)        {            if (a[i]>='0'&&a[i]<='9')            {                if (a[i]-'0'>max) max=a[i]-'0';                s=s+a[i]-'0';            }            if (a[i]>='a'&&a[i]<='z')            {                if (a[i]-'a'+36>max) max=a[i]-'a'+36;                s=s+a[i]-'a'+36;            }            if (a[i]>='A'&&a[i]<='Z')            {                if (a[i]-'A'+10>max) max=a[i]-'A'+10;                s=s+a[i]-'A'+10;            }        }        d=false;        for(i=2;i<=62;i++)          if (s%(i-1)==0&&max<i) {d=true;break;}        if (d) printf("%d\n",i);        else        printf("such number is impossible!\n");    }    return 0;}


原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 耳朵被气堵住了怎么办 掏耳朵发炎了疼怎么办 掏耳朵掏深了疼怎么办 耳朵里进了虫子怎么办? 耳朵里飞进小虫怎么办 一只耳朵听力差怎么办 62岁耳朵有点聋怎么办 一支耳朵有点聋怎么办 80岁老人耳朵聋怎么办 被nlp课程洗脑了怎么办 手上张了个鸡眼怎么办 手上长了个鸡眼怎么办 6岁儿童手指脱皮怎么办 手指骨折后关节僵硬怎么办 手指外伤后关节肿大僵硬怎么办 胳膊骨折了手肿怎么办 耳朵被肘了耳鸣怎么办 耳朵鼓膜外显的怎么办 耳膜破了怎么办为好 耳朵的鼓膜破了怎么办 被打耳鼓膜穿孔怎么办 两只耳朵嗡嗡响怎么办 耳朵长了个脓包怎么办 胸一个大一个小怎么办 把耳朵掏出血了怎么办 掏耳朵戳出血了怎么办 耳朵戳伤流血了怎么办 耳朵挖破出血了怎么办 耳朵让耳屎堵了怎么办 手被牙齿划破了怎么办 耳朵掏伤了很痛怎么办 掏伤耳朵发炎了怎么办 耳朵被掏发炎了怎么办 打的耳洞化脓了怎么办 打了耳洞流脓了怎么办 打了耳洞发炎怎么办 打了耳洞化脓了怎么办 3岁宝宝耳朵流脓怎么办 耳朵里面是湿的怎么办 耳朵里天天很痒怎么办 身上长湿疹很痒怎么办