标签:
input | output |
---|---|
127 16 |
3 |
1 /** 2 Create By yzx - stupidboy 3 */ 4 #include <cstdio> 5 #include <cstring> 6 #include <cstdlib> 7 #include <cmath> 8 #include <deque> 9 #include <vector> 10 #include <queue> 11 #include <iostream> 12 #include <algorithm> 13 #include <map> 14 #include <set> 15 #include <ctime> 16 #include <iomanip> 17 using namespace std; 18 typedef long long LL; 19 typedef double DB; 20 #define MIT (2147483647) 21 #define INF (1000000001) 22 #define MLL (1000000000000000001LL) 23 #define sz(x) ((int) (x).size()) 24 #define clr(x, y) memset(x, y, sizeof(x)) 25 #define puf push_front 26 #define pub push_back 27 #define pof pop_front 28 #define pob pop_back 29 #define ft first 30 #define sd second 31 #define mk make_pair 32 33 inline int Getint() 34 { 35 int Ret = 0; 36 char Ch = ‘ ‘; 37 bool Flag = 0; 38 while(!(Ch >= ‘0‘ && Ch <= ‘9‘)) 39 { 40 if(Ch == ‘-‘) Flag ^= 1; 41 Ch = getchar(); 42 } 43 while(Ch >= ‘0‘ && Ch <= ‘9‘) 44 { 45 Ret = Ret * 10 + Ch - ‘0‘; 46 Ch = getchar(); 47 } 48 return Flag ? -Ret : Ret; 49 } 50 51 const int N = 30; 52 int x, y; 53 int arr[N], len1, brr[N], len2; 54 55 inline void Input() 56 { 57 cin >> x >> y; 58 } 59 60 inline void Change(int *a, int &len, int x, int base) 61 { 62 len = 0; 63 while(x) 64 { 65 a[len++] = x % base; 66 x /= base; 67 } 68 } 69 70 inline void Solve() 71 { 72 for(int k = 2; k <= x; k++) 73 { 74 Change(arr, len1, x, k); 75 Change(brr, len2, y, k); 76 77 int index = 0; 78 bool flag = 1; 79 for(int j = 0; j < len2; j++) 80 { 81 while(index < len1 && arr[index] != brr[j]) 82 index++; 83 if(index < len1) index++; 84 else 85 { 86 flag = 0; 87 break; 88 } 89 } 90 if(flag) 91 { 92 printf("%d\n", k); 93 return; 94 } 95 } 96 printf("No solution\n"); 97 } 98 99 int main() 100 { 101 freopen("c.in", "r", stdin); 102 Input(); 103 Solve(); 104 return 0; 105 }
标签:
原文地址:http://www.cnblogs.com/StupidBoy/p/5076818.html