思维题
题意:
给你一个区间[L,R],问是否可以按题目操作K次内使得区间的最小公因数大于1
可以进行
1.选择两个数进行运算,然后放入区间,样例是把这两个数相乘
2.可以删除其中一个数
3.把区间在插入区间一次
分析:
要让最小公因数大于1,说明最小要是2,而且题目范围很大,肯定不是暴力做的,就是动动脑的题,区间[x,x+1,x+2,x+3.....]的一个区间肯定最小公因数为1,由于最小公因数是2,自然而然的奇数就不行,就需要除去,因此这个题就是不断的进行2,让奇数都删除,剩下的数的最小公因数就是2,当然也就复合条件了。
代码:
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<cstdio>
#include<cstring>
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define PII pair<int,int>
typedef long long ll;
using namespace std;
int l,r,t,k;
int gcd(int a,int b)
{
if(!b) return a;
return gcd(b,a % b);
}
void solve()
{
if(l == r && l > 1){ //特殊情况可以直接出答案
cout << "YES" << endl;
return ;
}
if(l == r && l == 1) {
cout << "NO" << endl;
return ;
}
int mi; //最小需要进行的操作次数
if(r & 1) mi = r / 2;
else mi = (r - 1) / 2 + 1;
if(l & 1) mi -= l / 2;
else mi -= l / 2 - 1;
//cout << mi << endl; //偶数的个数,前r个偶数减去前l个就是[l,r]区间的偶数
mi = r - l + 1 - mi;
if(k >= mi) cout << "YES" << endl;
else cout << "NO" << endl;
}
int main(){
IOS;
cin >> t;
while(t--){
cin >> l >> r >> k;
solve();
}
return 0;
}