http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1116
分析:
暴力直接求 注意是从几进制开始的
AC代码:
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include<list>
#include <bitset>
#include <climits>
#include <algorithm>
#define gcd(a,b) __gcd(a,b)
#define FIN freopen("111.txt","r",stdin)
#define FOUT freopen("output.txt","w",stdout)
typedef long long LL;
const LL mod=1e9+7;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
using namespace std;
char str[1000005];
LL a[1000005];
int main (){
// FIN;
while (scanf ("%s",str)!=EOF){
int n=strlen(str);
int flag=0;
int len=0;
int maxn=-1;
for (int i=0;i<n;i++){
if (str[i]>='A'&&str[i]<='Z') {
maxn=max(maxn,str[i]-'A'+10);
a[len++]=str[i]-'A'+10,flag=1;
}
else if (str[i]>='a'&&str[i]<='z') {
maxn=max(maxn,str[i]-'a'+10);
a[len++]=str[i]-'a'+10,flag=1;
}
else a[len++]=str[i]-'0';
}
int ff=0;
if (!flag){
for (int i=2;i<=37;i++){
LL temp=0;
for (int j=0;j<len;j++)
temp=(temp%(i-1)*i+a[j])%(i-1);
if (temp==0){
printf ("%d\n",i);
ff=1;break;
}
}
}
else {
for (int i=maxn+1;i<=37;i++){
LL temp=0;
for (int j=0;j<len;j++)
temp=(temp%(i-1)*i+a[j])%(i-1);
if (temp==0){
printf ("%d\n",i);
ff=1;break;
}
}
}
if (!ff) printf ("No Solution\n");
}
return 0;
}