An Easy Problem!
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 9115 | Accepted: 2324 |
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.
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
题意:
是给你一个N进制的整数R,题目保证R能被N-1整除,让你求符合条件的最小的N。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char a[233333];
int main()
{
while(scanf("%s", a+1) != EOF)
{
int b, sum=0, n = -1;
int len = strlen(a+1);
for(int i = 1;i <= len;i ++)
{
if(a[i] >= '0' && a[i] <= '9')
{
b = a[i] - '0';
}
else if(a[i] >= 'A' && a[i] <= 'Z')
{
b = a[i] - 'A' + 10;
}
else if(a[i] >= 'a' && a[i] <= 'z')
{
b = a[i] - 'a' + 36;
}
sum += b;
if(b > n)
n = b;
}
bool flag = 0;
for(int i = 2;i <= 62;i ++)
{
if(sum % (i-1) == 0 && n < i)
{
printf("%d\n", i);
flag = 1;
break;
}
}
if(flag == 0)
printf("such number is impossible!\n");
}
return 0;
}