Relatively Prime Pairs (CodeForces 1051B)

欢迎访问https://blog.csdn.net/lxt_Lucia~~

宇宙第一小仙女\(^o^)/~~萌量爆表求带飞=≡Σ((( つ^o^)つ~ dalao们点个关注呗~~

 

 

Description

You are given a set of all integers from ll to rr inclusive, l

You want to split these numbers into exactly r−l+12r−l+12 pairs in such a way that for each pair (i,j)(i,j) the greatest common divisor of ii and jj is equal to 11. 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.

 

Input

The only line contains two integers ll and rr (1 ≤ l < r ≤ 1e18 , r − l + 1 ≤ 3⋅1e5 , r − l + 1 ≤ 3⋅1e5 , (r−l)*(r−l) is odd).

 

Output

If any solution exists, print "YES" in the first line. Each of the next r−l+12r−l+12 lines should contain some pair of integers. GCD of numbers in each pair should be equal to 11. All (r−l+1)(r−l+1) numbers should be pairwise distinct and should have values from ll to rr inclusive.

If there are multiple solutions, print any of them.

If there exists no solution, print "NO".

 

Sample Input

Input

1 8

Output

YES
2 7
4 1
3 8
6 5

 

题意:

[ l , r ] 区间内可能还出现的所有相对素数对,求素数对数量最多的时候的相对素数对,如果有多种情况,输出其中一种。

 

思路:

有一个很精秒的想法,相邻的两个数一定是相对素数对,也是数量最多的时候,所以输出直接按照 [ l , r ] 区间内的相邻数就可以了,但是数字不能重复。

 

代码:

#include
int main()
{
    long long l,r;
    scanf("%lld %lld",&l,&r);
    printf("YES\n");
    for(long long i=l; i<=r; i+=2)
        printf("%lld %lld\n",i,i+1);
    return 0;
}

 

 

宇宙第一小仙女\(^o^)/~~萌量爆表求带飞=≡Σ((( つ^o^)つ~

dalao们点个关注呗~~

 

 

你可能感兴趣的:(spiny)