-
Notifications
You must be signed in to change notification settings - Fork 0
/
A1010_2.cpp
49 lines (43 loc) · 981 Bytes
/
A1010_2.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
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
char rule[36] = {'0','1','2','3','4','5','6','7','8','9','a','b',\
'c','d','e','f','g','h','i','j','k','l','m','n','o',\
'p','q','r','s','t','u','v','w','x','y','z'};
//进制转换专用,全部转化为10进制
long long convert(char N[],int r) {
long long value = 0;
for(int i=0;i<strlen(N);i++){
int number =0;
if(N[i] >='0' && N[i]<='9'){
number = N[i] - '0';
}
else if(N[i] >='a' && N[i] <= 'z'){
number = N[i] - 'a' +10;
}
value = (long long)value*r + number;
}
return value;
}
int main(){
char N1[12],N2[12];
int t,r;
long long value;
scanf("%s %s %d %d",&N1,&N2,&t,&r);
if(t==1) value = convert(N1,r);
else{
value = convert(N2,r);
strcpy(N2,N1);
}
bool flag = false;
for(r=2;r<100000 && flag == false;r++){
long long result = convert(N2,r);
if(result==value){
flag = true;
}
}
if(flag) printf("%d",r);
else printf("Impossible");
return 0;
}