poj 1152
来源:互联网 发布:微信cms系统 编辑:程序博客网 时间:2024/05/16 05:26
Description
You will be given an N based integer number R and you are given the guaranty that R is divisible by (N-1). You will have to print the smallest possible value for N. The range for N is 2 <= N <= 62 and the digit symbols for 62 based number is (0..9 and A..Z and a..z). Similarly, the digit symbols for 61 based number system is (0..9 and A..Z and a..y) and so on.
Input
Output
Sample Input
35A
Sample Output
4611
Source
/*
http://acm.pku.edu.cn/JudgeOnline/problem?id=1152
数论知识
给定一个N进制数R(ri, ri-1, ri-1, ... , r2, r1, r0)
则 R = ri * (N ^ i) + ri-1 * (N ^ i-1) + ri-2 * (N ^ i - 2) + ... + r2 * (N ^ 2) + r1 * (N ^ 1) + r0 * (N ^ 0)
= ri * {[(N - 1) + 1] ^ i} + ri-1 * {[(N - 1) + 1] ^ i-1} + ri-2 * {[(N - 1) + 1] ^ i - 2} + ... + r2 * {[(N - 1) + 1] * ^ 2} + r1 * {[(N - 1) + 1] ^ 1} + r0 * {[(N - 1) + 1] ^ 0}
所以 R mod (N - 1) = (ri + ri-1 + ri-2 + ... + r2 + r1 + r0) mod (N - 1)
so, the rest of the work is really easy...
不过要注意输入为单个0的情况,由于N必须>=2, 所以0应该输出2
*/
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
using namespace std;
int main()
{
string str;
while(cin>>str)
{
int sum=0, num=-1, len=str.size();
for(int i=0;i<len;i++)
{
int cnt;
if(str[i]>='0'&&str[i]<='9')
{
cnt=(str[i]-'0');
}
else if(str[i]>='a'&&str[i]<='z')
{
cnt=(str[i]-'a')+36;
}
else
{
cnt=(str[i]-'A')+10;
}
sum+=cnt;
num=max(num,cnt);
}
int i;
for(i=num;i<=61;i++)
{
if(sum%i==0)
{
printf("%d\n",i+1);
break;
}
}
if(i>=62)
{
printf("such number is impossible!\n");
}
}
return 0;
}
- poj 1152
- poj-1152
- poj 1152
- POJ——1152
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- POJ
- poj
- POJ
- POJ
- POJ
- POJ
- POJ
- Mac 上安装 Office 2016 破解版
- 错误讯息:检索 COM 类工厂中 CLSID 为 {00024500-0000-0000-C000-000000000046} 的组件失败,原因是出现以下错误: 80070005 拒绝访问。 (异常来
- Spring 学习系列 -- Spring + Mybatis 从零开始配置多数据源访问
- 【985系列】985的方格难题
- POJ 1328Radar Installation
- poj 1152
- RXAndroid入门
- AT&T Device Conformance Requirements - Knowledge Points
- HDU Problem 2546 饭卡【01背包】
- GDOI 8.11~8.14训练总结
- 谈谈:javascript:return 理解
- CodeForces 629BFar Relative’s Problem
- leetcode 349. Intersection of Two Arrays
- js判断PC端和移动端