-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy path10093.cpp
55 lines (43 loc) · 1.2 KB
/
10093.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <iostream>
#include <string>
using namespace std;
string NUMS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
/*
* returns a pair of values:
* sum of all chars in the string in decimal
* minimum possible base
*/
pair<int,int> count_sum(string &s) {
pair<int,int> result = make_pair(0,0);
size_t found;
for (int i = 0, sz = s.size(); i < sz; i++) {
found = NUMS.find(s[i]);
result.first += int(found);
if (int(found) > result.second)
result.second = int(found);
}
return result;
}
int main(void) {
string number;
while (cin >> number) {
if (number[0] == '-' || number[0] == '+')
number = string(number.begin() + 1, number.end());
pair<int,int> p = count_sum(number);
bool found = false;
// special case
if (p.second == 0)
p.second = 1;
for (int i = p.second + 1; i < 63; i++) {
if (p.first % (i-1) == 0) {
cout << i << endl;
found = true;
break;
}
}
if (!found) {
cout << "such number is impossible!" << endl;
}
}
return 0;
}