Get AC in one go
All submissions for this problem are available.
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.
- 1 <= t <= 106
- 1 <= a <= 109
- 1 <= b <= 109
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.
For each test case, print the required answer
Input: 1 4 7 6 1 2 4 Output: 18 0 -1
NOTE:Prefer fast input/output methods
|Tags||copr16, easy, gcd, likecs, likecs|
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, R, COB, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.