题目链接:URAL 1104
解题思路:
思路就是简单的模运算规则:( a * b ) % c = ( ( a % c ) * (b % c ) ) % c
根据上述规则,有如下规律:( a * b^n ) % ( b - 1 ) = a % ( b - 1 )
所以只要所有位上数字之和为b-1的倍数即可。
代码:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int len, base, ans, num;
char st[1000005];
int main()
{
while(~scanf("%s", st))
{
len = strlen(st), base = 1, ans = 0, num;
for(int i=0;i<len;i++)
{
if(st[i] >= 'A')
num = st[i]-'A'+10;
else
num = st[i]-'0';
ans += num;
base = max(base, num);
}
base++;
int flag = 0;
while(base<=36)
{
if(ans%(base-1)==0)
break;
base++;
}
if(base>36)
printf("No solution.\n");
else
printf("%d\n", base);
}
return 0;
}
总结:数论的简单推导