POJ 1152 An Easy Problem
2009-09-28 12:51
483 查看
An Easy Problem!
Description
Have you heard the fact "The base of every normal number system is 10" ? Of course, I am not talking about number systems like Stern Brockot Number System. This problem has nothing to do with this fact but may have some similarity.
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
Each line in the input will contain an integer (as defined in mathematics) number of any integer base (2..62). You will have to determine what is the smallest possible base of that number for the given conditions. No invalid number will be given as input. The largest size of the input file will be 32KB.
Output
If number with such condition is not possible output the line "such number is impossible!" For each line of input there will be only a single line of output. The output will always be in decimal number system.
Sample Input
Sample Output
Source
uva 10093
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 6264 | Accepted: 1429 |
Have you heard the fact "The base of every normal number system is 10" ? Of course, I am not talking about number systems like Stern Brockot Number System. This problem has nothing to do with this fact but may have some similarity.
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
Each line in the input will contain an integer (as defined in mathematics) number of any integer base (2..62). You will have to determine what is the smallest possible base of that number for the given conditions. No invalid number will be given as input. The largest size of the input file will be 32KB.
Output
If number with such condition is not possible output the line "such number is impossible!" For each line of input there will be only a single line of output. The output will always be in decimal number system.
Sample Input
3 5 A
Sample Output
4 6 11
Source
uva 10093
/* 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 <string> using namespace std; int main() { int p, maxNum; string input; char ch; while(cin>>input) { int total = 0, curNum; maxNum = INT_MIN; for(p = 0; p < input.length(); p++) { ch = input[p]; if(ch >= '0' && ch <= '9') curNum = int(ch - '0'); else if(ch >= 'A' && ch <= 'Z') curNum = (ch - 'A') + 10; else curNum = (ch - 'a') + 36; if(curNum > maxNum) maxNum = curNum; total += curNum; } if(maxNum == 0) maxNum = 1; for(p = maxNum; p <= 61; p++) { if(total % p == 0) { cout<<p + 1; break; } } if(p > 61) cout<<"such number is impossible!"; cout<<endl; } return 0; }
相关文章推荐
- POJ 1152 An Easy Problem!(进位制)
- POJ 1152 An Easy Problem! (取模运算性质)
- poj-1152 An Easy Problem!
- POJ-1152 An Easy Problem! 解题报告(数论) 是不是N进制数
- poj_1152_An Easy Problem!(进制)
- POJ 1152 An Easy Problem! 笔记
- Poj 1152 An Easy Problem!
- poj——1152——An Easy Problem!
- POJ 1152 An Easy Problem! (取模运算性质)
- 简单几何(线段相交) POJ 2826 An Easy Problem?!
- POJ 2826 || an easy problem ?!(未AC,呵呵~
- An Easy Problem?! POJ - 2826 (几何)
- POJ 2826 An Easy Problem?!
- Poj 2826 An Easy Problem?!
- POJ 2826 An Easy Problem?!(线段交点+简单计算)
- POJ 2826 An Easy Problem?!
- POJ 2826 An Easy Problem?!
- POJ 2826 An Easy Problem?! --计算几何,叉积
- An Easy Problem?! POJ 2826 计算几何
- 【POJ 2826】An Easy Problem?!(几何、线段)