题意:一个大数是k进制并且是(k - 1)的倍数,求出最小的k;
思路:当为k进制的时候,因为k % (k - 1) == 1,k ^ k % (k - 1) == 1,……,所以这个大数每位的权取模之后全是一,所以要判断k进制数是否是(k - 1)的倍数的话直接将各个数相加,判断一下是否是(k - 1)的倍数就行。
COde:
#include<iostream> #include<cstdio> #include<queue> #include<cstring> using namespace std; typedef long long ll; const int maxn = 1000000 + 2; #define INF 0x3f3f3f3f #define clr(x,y) memset(x,y,sizeof x) char s[maxn]; int main() { while( ~ scanf("%s",s)) { int len = strlen(s); int sum = 0; int maxs = 1; for(int i = 0; i < len; i ++) if(s[i] >= '0' && s[i] <= '9') sum += s[i] - '0',maxs = max(maxs,s[i] - '0'); else sum += s[i] - 'A' + 10,s[i] -'A' + 10 ); int ans = -1; for(int i = max(2,maxs + 1); i <= 36; i ++) { if(sum % (i - 1) == 0) { ans = i; break; } } if(ans == -1) puts("No Solution"); else cout << ans << endl; } return 0; }