温故知新:互质排列

每次询问给你一个区间[l,r],你有l,l+1,l+2,...,r这r-l+1数,现在问你这些数是否存在一种排列p1,p2...pn使得pi与pi+1互质。特别的要保证p1和pn也互质。 

题目地址:http://192.168.173.163/JudgeOnline/problem.php?cid=1244&pid=7

题目分析:

 

我的代码:

#include <cstdio>
using namespace std;
 
int main()
{
    int T,l,r;
    scanf("%d",&T);
    while (T--)
    {
        scanf("%d%d",&l,&r);
        if(l%2==0&&r%2==0) puts("NO");
        else if(l%3==0&&r%3==0&&r-l+1==4) puts("NO") ;
        else puts("YES");
    }
    return 0;
}

  

 

猜你喜欢

转载自www.cnblogs.com/dragondragon/p/11373382.html