-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathint_128.cpp
More file actions
69 lines (57 loc) · 1.12 KB
/
int_128.cpp
File metadata and controls
69 lines (57 loc) · 1.12 KB
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
#define ll __int128
inline ll POW(ll n, ll k)
{
ll ans = 1;
while (k) // this program find out gcd of x and y
{
if (k & 1)
ans = ans * n;
n = n * n;
k >>= 1;
}
return ans;
}
ll gcd(ll a, ll b) {
while (b != 0) {
ll temp = b;
b = a % b;
a = temp;
}
return a;
}
// Function to print __int128 (since cout doesn't support __int128)
void print128(ll value) {
if (value == 0) {
cout << 0;
return;
}
string result = "";
while (value > 0) {
result += (char)('0' + value % 10);
value /= 10;
}
reverse(result.begin(), result.end());
cout << result;
}
//////
// Driver Code
int main()
{
Faster;
int tc = 1, test = 1;
cin >> tc;
while (tc--)
{
long long x, y;
cin >> x >> y;
ll a = POW((ll)x,(ll)6);
ll b = POW((ll)y,(ll)6);
ll c = POW((ll)x,(ll)4);
ll d = POW((ll)y,(ll)4);
ll m = a - b;
ll n = c - d;
ll res = gcd(m,n);
print128(res);
cout << endl;
}
}