codeforces-scrape

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

1051B.md (1289B)


      1 Source: https://codeforces.com/problemset/problem/1051/B
      2 
      3 B. Relatively Prime Pairs
      4 
      5 time limit per test
      6 
      7 2 seconds
      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 a set of all integers from $l$ to $r$ inclusive, $l \lt r$, $(r - l + 1) \le 3 \cdot 10^5$ and $(r - l)$ is always odd.
     22 
     23 You want to split these numbers into exactly $\frac{r - l + 1}{2}$ pairs in such a way that for each pair $(i, j)$ the greatest common divisor of $i$ and $j$ is equal to $1$. Each number should appear in exactly one of the pairs.
     24 
     25 Print the resulting pairs or output that no solution exists. If there are multiple solutions, print any of them.
     26 
     27 Input
     28 
     29 The only line contains two integers $l$ and $r$ ($1 \le l \lt r \le 10^{18}$, $r - l + 1 \le 3 \cdot 10^5$, $(r - l)$ is odd).
     30 
     31 Output
     32 
     33 If any solution exists, print "YES" in the first line. Each of the next $\frac{r - l + 1}{2}$ lines should contain some pair of integers. GCD of numbers in each pair should be equal to $1$. All $(r - l + 1)$ numbers should be pairwise distinct and should have values from $l$ to $r$ inclusive.
     34 
     35 If there are multiple solutions, print any of them.
     36 
     37 If there exists no solution, print "NO".
     38 
     39 Example
     40 
     41 Input
     42 
     43 ```
     44 1 8
     45 ```
     46 
     47 Output
     48 
     49 ```
     50 YES  
     51 2 7  
     52 4 1  
     53 3 8  
     54 6 5
     55 ```