`{"id":"e12c3fdc-f5dc-4921-af95-60211be9e429","name":"Relatively Prime Pairs","description":"You are given a set of all integers from l to r inclusive (r - l is odd).You want to split these numbers into exactly (r-l+1)/2 pairs in such a way that for each pair (i,j), the greates common divisor of i and j is equal to 1.\r\nEach pair should appear in exactly one of the pairs.\r\n\r\nPrint the resulting pairs or output that no solution exists.","inputFormat":"The only line contains two integer l and r.","outputFormat":"If any solution exists, print \"YES\" in the first line. Each of next (r-l+1)/2 line contains some pair of integers. GCD of each pair of integers should be equal to 1.\r\nIf there exists no solution print \"NO\".","constraints":"1 &lt;= l, r, &lt;= 10^8\r\nr-l+1 &lt;= 10^5 and r-l is odd","sampleCode":{"cpp":{"code":""},"java":{"code":"\r\nimport java.util.*;\r\nimport java.util.function.Function;\r\nimport java.util.stream.Collectors;\r\nimport java.io.*;\r\nimport java.math.*;\r\n\r\npublic class Main {\r\n\t\tpublic static void main(String[] args) {\r\n\r\n\t}\r\n}\r\n"},"ruby":{"code":""},"python":{"code":""},"javascript":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"1 8\r\n","sampleOutput":"YES\r\n1 2\r\n3 4\r\n5 6\r\n7 8\r\n\r\n","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"086949fa-3c5e-40c6-8a9c-f9be4b400318","name":"Number Theory For Experts","slug":"number-theory-for-experts","type":0},{"id":"d8bd2d16-c0f4-4976-a080-a1eea0465200","name":"Relatively Prime Pairs","slug":"relatively-prime-pairs","type":1}],"next":{"id":"b3bdd6a6-75eb-452b-bb32-135945f99b12","name":"Sum Of Factors","type":1,"slug":"sum-of-factors"},"prev":{"id":"c406e72a-1c68-4993-b98b-2a51ad2de329","name":" I Hate 1111","type":1,"slug":"i-hate-1111"}}}`

# Relatively Prime Pairs

You are given a set of all integers from l to r inclusive (r - l is odd).You want to split these numbers into exactly (r-l+1)/2 pairs in such a way that for each pair (i,j), the greates common divisor of i and j is equal to 1. Each pair should appear in exactly one of the pairs. Print the resulting pairs or output that no solution exists.

`{"id":"e12c3fdc-f5dc-4921-af95-60211be9e429","name":"Relatively Prime Pairs","description":"You are given a set of all integers from l to r inclusive (r - l is odd).You want to split these numbers into exactly (r-l+1)/2 pairs in such a way that for each pair (i,j), the greates common divisor of i and j is equal to 1.\r\nEach pair should appear in exactly one of the pairs.\r\n\r\nPrint the resulting pairs or output that no solution exists.","inputFormat":"The only line contains two integer l and r.","outputFormat":"If any solution exists, print \"YES\" in the first line. Each of next (r-l+1)/2 line contains some pair of integers. GCD of each pair of integers should be equal to 1.\r\nIf there exists no solution print \"NO\".","constraints":"1 &lt;= l, r, &lt;= 10^8\r\nr-l+1 &lt;= 10^5 and r-l is odd","sampleCode":{"cpp":{"code":""},"java":{"code":"\r\nimport java.util.*;\r\nimport java.util.function.Function;\r\nimport java.util.stream.Collectors;\r\nimport java.io.*;\r\nimport java.math.*;\r\n\r\npublic class Main {\r\n\t\tpublic static void main(String[] args) {\r\n\r\n\t}\r\n}\r\n"},"ruby":{"code":""},"python":{"code":""},"javascript":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"1 8\r\n","sampleOutput":"YES\r\n1 2\r\n3 4\r\n5 6\r\n7 8\r\n\r\n","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"086949fa-3c5e-40c6-8a9c-f9be4b400318","name":"Number Theory For Experts","slug":"number-theory-for-experts","type":0},{"id":"d8bd2d16-c0f4-4976-a080-a1eea0465200","name":"Relatively Prime Pairs","slug":"relatively-prime-pairs","type":1}],"next":{"id":"b3bdd6a6-75eb-452b-bb32-135945f99b12","name":"Sum Of Factors","type":1,"slug":"sum-of-factors"},"prev":{"id":"c406e72a-1c68-4993-b98b-2a51ad2de329","name":" I Hate 1111","type":1,"slug":"i-hate-1111"}}}`

Editor

# Relatively Prime Pairs

medium

You are given a set of all integers from l to r inclusive (r - l is odd).You want to split these numbers into exactly (r-l+1)/2 pairs in such a way that for each pair (i,j), the greates common divisor of i and j is equal to 1. Each pair should appear in exactly one of the pairs. Print the resulting pairs or output that no solution exists.

## Constraints

1 <= l, r, <= 10^8 r-l+1 <= 10^5 and r-l is odd

## Format

### Input

The only line contains two integer l and r.

### Output

If any solution exists, print "YES" in the first line. Each of next (r-l+1)/2 line contains some pair of integers. GCD of each pair of integers should be equal to 1. If there exists no solution print "NO".

## Example

Sample Input

```.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}1 8 ```

### Sample Output

```.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}YES 1 2 3 4 5 6 7 8 ```

Discussions

Show Discussion

Related Resources