51Nod 1116 K进制下的大数(暴力枚举)
1 #include<iostream> 2 #include<cstdio> 3 #include<algorithm> 4 #include<cstring> 5 6 using namespace std; 7 const int maxn = 1e5 + 100; 8 char str[maxn]; 9 int a[maxn]; 10 11 int main() 12 { 13 int n, i, j, ans, t, tt, ttt, mod; 14 scanf("%s", str); 15 n = strlen(str); 16 ans = 2; 17 j = 0; 18 for (i = n - 1; i >= 0; i--) { 19 if (str[i] >= '0'&&str[i] <= '9') { 20 a[j] = str[i] - '0'; 21 ans = max(ans, a[j] + 1); 22 } 23 else { 24 a[j] = str[i] - 'A' + 10; 25 ans = max(ans, a[j] + 1); 26 } 27 j++; 28 } 29 a[j] = '\0'; 30 for (; ans<37; ans++) { 31 t = 0; 32 tt = 1; 33 mod = ans - 1; 34 for (i = 0; i<n; i++) { 35 t = (t + a[i] * tt%mod) % mod; 36 tt = tt*ans%mod; 37 } 38 if (t == 0) break; 39 } 40 if (ans < 37) 41 printf("%d\n", ans); 42 else 43 printf("No Solution\n"); 44 return 0; 45 }