codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1872C.md (1846B)


      1 Source: https://codeforces.com/problemset/problem/1872/C
      2 
      3 C. Non-coprime Split
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 You are given two integers $l \le r$. You need to find positive integers $a$ and $b$ such that the following conditions are simultaneously satisfied:
     22 
     23 * $l \le a + b \le r$
     24 * $\gcd(a, b) \neq 1$
     25 
     26 or report that they do not exist.
     27 
     28 $\gcd(a, b)$ denotes the [greatest common divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor) of numbers $a$ and $b$. For example, $\gcd(6, 9) = 3$, $\gcd(8, 9) = 1$, $\gcd(4, 2) = 2$.
     29 
     30 Input
     31 
     32 The first line of the input contains an integer $t$ ($1 \le t \le 500$) — the number of test cases.
     33 
     34 Then the descriptions of the test cases follow.
     35 
     36 The only line of the description of each test case contains $2$ integers $l, r$ ($1 \le l \le r \le 10^7$).
     37 
     38 Output
     39 
     40 For each test case, output the integers $a, b$ that satisfy all the conditions on a separate line. If there is no answer, instead output a single number $-1$.
     41 
     42 If there are multiple answers, you can output any of them.
     43 
     44 Example
     45 
     46 Input
     47 
     48 ```
     49 11
     50 
     51 11 15
     52 
     53 1 3
     54 
     55 18 19
     56 
     57 41 43
     58 
     59 777 777
     60 
     61 8000000 10000000
     62 
     63 2000 2023
     64 
     65 1791791 1791791
     66 
     67 1 4
     68 
     69 2 3
     70 
     71 9840769 9840769
     72 ```
     73 
     74 Output
     75 
     76 ```
     77 6 9
     78 -1
     79 14 4
     80 36 6
     81 111 666
     82 4000000 5000000 
     83 2009 7
     84 -1
     85 2 2
     86 -1
     87 6274 9834495
     88 ```
     89 
     90 Note
     91 
     92 In the first test case, $11 \le 6 + 9 \le 15$, $\gcd(6, 9) = 3$, and all conditions are satisfied. Note that this is not the only possible answer, for example, $\{4, 10\}, \{5, 10\}, \{6, 6\}$ are also valid answers for this test case.
     93 
     94 In the second test case, the only pairs $\{a, b\}$ that satisfy the condition $1 \le a + b \le 3$ are $\{1, 1\}, \{1, 2\}, \{2, 1\}$, but in each of these pairs $\gcd(a, b)$ equals $1$, so there is no answer.
     95 
     96 In the third sample test, $\gcd(14, 4) = 2$.