Codeforces--1051B--Relatively Prime Pairs


タイトル説明:You are given a set of all integers from l to r inclusive,l
You want to split these numbers into exactly r−l+12 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.
Print the resulting pairs or output that no solution exists. If there are multiple solutions, print any of them. 入力説明:The only line contains two integers l and r(1≦l出力説明:If any solution exists,print"YES"in the first line.Each of the next r−l+12 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.
If there are multiple solutions, print any of them.
If there exists no solution, print “NO”. 入力:4 8 5 2 3 6 1 1 1 2 2出力:164 27題意:区間内で対数が互いに質数であることを尋ねる.1つの数と彼の隣接する数は必ず互いに質数であり、列挙すればよい.コード:
#include
#include
#include
#include
using namespace std;

typedef long long ll;

int main(){
    ll l,r;
    while(scanf("%lld%lld",&l,&r)!=EOF){
        printf("YES
"
); for(ll i = l;i < r;i += 2){ printf("%I64d %I64d
"
,i,i + 1); } } return 0; }