2019ICPC徐州 C < 3 numbers题解

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;
        }
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值