-
Notifications
You must be signed in to change notification settings - Fork 0
/
cf_B.cpp
93 lines (87 loc) · 1.92 KB
/
cf_B.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/* Ankit Srivastava */
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define FF first
#define SS second
#define s(n) scanf("%d",&n)
#define sl(n) scanf("%lld",&n)
#define sf(n) scanf("%lf",&n)
#define ss(n) scanf("%s",n)
#define sc(n) {char temp[4]; ss(temp); n=temp[0];}
#define INF (int)1e9
#define LINF (long long)1e18
#define EPS 1e-9
#define maX(a,b) ((a)>(b)?(a):(b))
#define miN(a,b) ((a)<(b)?(a):(b))
#define abS(x) ((x)<0?-(x):(x))
typedef long long ll;
typedef unsigned long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
typedef pair<int,PII> TRI;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<ll> vl;
typedef vector<PII> VII;
typedef vector<TRI> VT;
int p, q;
int TEST_NO;
void precompute() {
}
void read() {
s(p), s(q);
}
void preprocess() {
}
void printAns(int i, int ai) {
printf("%d ", ai);
for (int j = 0; j < i - 1; ++j)
{
printf("%d ", 0);
}
printf("%d\n", p - ai);
}
void solveCrux() {
int d = q - p;
ll ex = p;
int cnt = 0, ind = 0, ais = 0;
for (int i = 1; i < 32; ++i) {
int den = ex - 1;
if(d % den == 0) {
int ai = (d / den);
if(p - ai > 0) {
cnt ++;
ind = i;
ais = ai;
}
}
ex *= p;
}
if(cnt == 0) puts("IMPOSSIBLE");
else if(cnt == 1) printAns(ind, ais);
else puts("AMBIGUOUS");
}
void solve() {
if(q < p) puts("IMPOSSIBLE");
else if(q == p) {
printf("%d\n", p);
}
else if(p <= 1) puts("IMPOSSIBLE");
else {
solveCrux();
}
}
int main() {
precompute();
int t;
s(t);
for(TEST_NO = 1; TEST_NO <= t; TEST_NO ++) {
read();
preprocess();
solve();
}
return 0;
}