2019ICPC徐州 C < 3 numbers题解
题目链接:https://nanti.jisuanke.com/t/42542
题目大意:T组询问,每次给一个L,R,问在 [L,R] 区间内的所有数中,是否有小于三分之一的数满足:这个数的因子的个数小于三
T :100 ; L,R :1e9
一个数的因子个数小于3,首先想到是素数,1也是符合条件的,因为LR比较大,直接猜想如果R-L+1大过某个值的时候就不可能有超过1/3的数满足,队友简单打了个表发现确实是这样子,对于R-L+1>100的询问直接输出yes,剩下的暴力判定一下就行了。
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define IO std::ios::sync_with_stdio(false);cin.tie(0)
#define endl '\n'
#define lb(x) x&(-x)
#define pii pair<int,int>
#define pll pair<ll,ll>
using namespace std;
const double pi = 3.141592653589793238462;
const int maxn = 1e5+5;
const double eps = 1e-18;
const ull base = 13331;
const ll mod = 998857459;
bool isp(ll x){
if(x == 2)return true;
for(ll i = 2;i*i<=x;i++){
if(x%i==0)return false;
}
return true;
}
bool check(ll l,ll r){
ll fm = r-l+1;
ll cnt = 0;
for(ll i = l;i<=r;i++){
if(isp(i))cnt++;
}
ll d = cnt*3;
if(d>=fm)return false;
return true;
}
int main(){
IO;
int t;
cin>>t;
while(t--){
ll l,r;
cin>>l>>r;
ll fm = (r-l+1);
if(fm>=100){
cout<<"Yes"<<endl;
continue;
}
if(check(l,r)){
cout<<"Yes"<<endl;
}
else {
cout<<"No"<<endl;
}
}
}