http://acm.timus.ru/problem.aspx?space=1&num=1104
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #define maxn 2000000 5 using namespace std; 6 7 char s1[maxn]; 8 9 int main() 10 { 11 scanf("%s",s1); 12 int k=strlen(s1); 13 char ch='+'; 14 int sum=0; 15 for(int i=0; i<k; i++) 16 { 17 if(s1[i]>ch) ch=s1[i]; 18 if(s1[i]>='0'&&s1[i]<='9') sum+=(s1[i]-'0'); 19 else if(s1[i]>='A'&&s1[i]<'Z') sum+=(s1[i]-'A'+10); 20 } 21 int c; 22 if(ch>='0'&&ch<='9') c=ch-'0'; 23 else c=ch-'A'+10; 24 if(c+1<2) c=2; 25 else c++; 26 for(; c<=36; c++) 27 { 28 if(sum%(c-1)==0) break; 29 } 30 if(c<=36) printf("%d ",c); 31 else if(c>36) printf("No solution. "); 32 return 0; 33 }