-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCOPR16G.cpp
56 lines (40 loc) · 1.02 KB
/
COPR16G.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
/*
The easiest problem of the lot !
You are provided with coins of denominations "a" and "b". You are required to find the least value of n, such that all currency values greater than or equal to n can be made using any number of coins of denomination "a" and "b" and in any order. If no such number exists, print "-1" in that case.
Input Constraints:
1 <= t <= 106
1 <= a <= 109
1 <= b <= 109
Input Format:
The first line contains t, the number of test cases.
Each of the next t lines contains 2 integers a & b, as specified in the question.
Output Format:
For each test case, print the required answer
Example
Input:
1
4 7
6 1
2 4
Output:
18
0
-1
NOTE:Prefer fast input/output methods
*/
#include<bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
long long a, b;
cin >> a >> b;
int g = __gcd(a, b);
if (g > 1) cout << -1 << "\n";
else cout << a * b - a - b + 1 << "\n"; // using chicken mcnugget theorem
}
return 0;
}