Mrs Little likes digits most of all. Every year she tries to make the best number of the year. She tries to become more and more intelligent and every year studies a new digit. And the number she makes is written in numeric system which base equals to her age. To make her life more beautiful she writes only numbers that are divisible by her age minus one. Mrs Little wants to hold her age in secret.
You are given a number consisting of digits 0, …, 9 and Latin letters A, …, Z, where A equals 10, B equals 11 etc. Your task is to find the minimal number k satisfying the following condition: the given number, written in k-based system is divisible by k−1.
Input
Input consists of one string containing no more than 106 digits or uppercase Latin letters.
Output
Output the only number k, or “No solution.” if for all 2 ≤ k ≤ 36 condition written above can’t be satisfied. By the way, you should write your answer in decimal system.
Sample
Input
A1A
outout
22

1.如果这个数(k进制数）能整除k-1，则这个数每位加起来也能整除k-1。

k=10,则为10进制数，99能整除k-1（即9），则9+9也能整除k-1（即9）；18能整除k-1（即9），则1+8也能整除k-1（即9）；

k=8,则为8进制数，115（10进制时为77）能整除k-1（即7），则1+1+5也能整除k-1(即7）

2.k一定大于字符串中最大的数字。这很好理解，10进制数，10一定大于10进制数中每一位数。

#include <iostream>
#include <string.h>
#include <stdio.h>

using namespace std;
char str[1000005];
int main()
{
while(gets(str))
{
int l=strlen(str);
int minbase=0;
int sum=0;
for(int i=0;i<l;i++)
{
if(str[i]>='0'&&str[i]<='9')
{
sum+=str[i]-'0';
if(str[i]-'0'>minbase)
minbase=str[i]-'0';
}
else
{
sum+=str[i]-'A'+10;
if(str[i]-'A'+10>minbase)
minbase=str[i]-'A'+10;
}
}
minbase++;
if(minbase<=2)
cout<<2<<endl;
else
{
int i;
for(i=minbase;i<=36;i++)
{
if(sum%(i-1)==0)
{
cout<<i<<endl;break;
}
}
if(i==36+1)
cout<<"No solution."<<endl;
}
}
return 0;
}

0