您的位置:首页 > 其它

URAL 1104(数论)

2015-09-28 22:42 369 查看
题目链接: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;
}


总结:数论的简单推导
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: