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的倍数即可。
代码:
总结:数论的简单推导
解题思路:
思路就是简单的模运算规则:( 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; }
总结:数论的简单推导
相关文章推荐
- Android 应用桌面快捷方式 创建 删除
- iOS解析XML
- NSIS 的 Modern UI 教程
- java面试题二十九 多线程数据共享问题
- JAVA Final
- POJ - 3186 Treats for the Cows(DP)
- Git笔记之通过ssh从git服务器拉取代码
- 好的习惯很重要
- java中的“回车”与“换行”
- 微软2014实习生及秋令营技术类职位在线测试-K-th string
- 装饰我的Linux ---Ubuntu Kylin 15.04
- 深入 HBase 架构解析(2)
- Ubuntu 中文输入法安装 ibus
- HDU 5493 Queue (2015年合肥赛区网络赛J题)
- Java中File类的例子
- EF学习和使用(六)显式加载、按需加载
- TabHost笔记
- SpringMVC获取静态资源的问题
- 修改mysql密码
- [HDU 5489]Removed Interval[LIS]