PKU 1152 An Easy Problem!
2009-08-27 20:47
330 查看
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
题目其实很简单,但是很有趣。假设一个数可以表示为∑ai * (base ^ i),这个数可以被n-1整除,那么∑ai也能被n-1整除,而且两者是等价的。
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
题目其实很简单,但是很有趣。假设一个数可以表示为∑ai * (base ^ i),这个数可以被n-1整除,那么∑ai也能被n-1整除,而且两者是等价的。
//#include "stdafx.h" //============================================================================ // Name : acmcpp.cpp // Author : Yubo Chow // Version : // Copyright : Your copyright notice // Description : Hello World in C++, Ansi-style //============================================================================ #include <iostream> #include <stdlib.h> #include <stdio.h> #include <queue> #include <math.h> #include <algorithm> #include <set> #include <limits.h> #include <float.h> #include <bitset> #include <cmath> #include <vector> #include <map> #include <list> #include <string.h> using namespace std; int main() { #ifndef ONLINE_JUDGE freopen("case.txt", "r", stdin); #endif char num[320000]; while (scanf("%s", num) == 1 && num[0]) { int len = 0, base = 1; int sum = 0; for (; num[len]; ++len) { if (num[len] <= '9') { num[len] -= '0'; } else if (num[len] <= 'Z') { num[len] -= 'A' - 10; } else { num[len] -= 'a' - 36; } base = max(base, int(num[len])); sum += num[len]; } for (++base; base < 63; ++base) { if (sum % (base - 1) == 0) { cout << base << endl; break; } } if (base == 63) { cout << "such number is impossible!" << endl; } } return 0; }
相关文章推荐
- pku 1152 An Easy Problem!
- POJ 1152 An Easy Problem!(进位制)
- POJ 1152 An Easy Problem! 笔记
- PKU 2453 An Easy Problem
- POJ 1152 An Easy Problem
- poj_1152_An Easy Problem!(进制)
- Poj 1152 An Easy Problem!
- poj——1152——An Easy Problem!
- 【解题报告】PKU 2826 An Easy Problem?!
- POJ 1152 An Easy Problem! (取模运算性质)
- poj-1152 An Easy Problem!
- POJ 1152 An Easy Problem! (取模运算性质)
- POJ-1152 An Easy Problem! 解题报告(数论) 是不是N进制数
- [POJ2826]An Easy Problem?!(计算几何)
- HDOJ 2055 An easy problem
- poj 2826 An Easy Problem?! (线段相交问题终极版...并不easy)
- DHUOJ - 2017060315 Problem O - An Easy Problem
- POJ2826-An Easy Problem?!
- HDU_2055 An easy problem
- HDOJ 5475 An easy problem(线段树)