栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

Primality Test 素数,打表

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Primality Test 素数,打表

  • 题意 : f ( x ) f(x) f(x)是严格大于x的最小质数, g ( x ) = [ f ( x ) + f ( f ( x ) ) ] / 2 g(x)=[f(x)+f(f(x))]/2 g(x)=[f(x)+f(f(x))]/2的向下取整,判断 g ( x ) g(x) g(x)是否是质数
  • 思路 :f(f(x))即f(x)相邻的下一个质数,g(x)在相邻两个质数之间,所以g(x)一定是合数,除了x=1的情况下,f(1)=2,f(2)=3,即除了2和3之间以外
  • 语法 :long long 9e18多,int 2e9多
#include 
#define endl 'n'

using namespace std;

typedef long long ll;

int main()
{
    int T;
    cin >> T;
    
    while (T -- )
    {
        ll x;
        cin >> x;
        if (x == 1) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    
    return 0;
}

//打表
#include
using namespace std;
typedef long long LL;

const int maxn = 1e9+10;

int is_prime(LL x){
    for(LL i = 2; i*i <= x; i++){
        if(x%i==0){
            return 0;
        }
    }
    return 1;
}

int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int T;  cin>>T;
    while(T--){
        LL x=T; // cin>>x;
        LL i;
        for(i = x+1; ; i++){
            if(is_prime(i)){
                break;
            }
        }
        LL j;
        for(j = i+1; ; j++){
            if(is_prime(j)){
                break;
            }
        }
        LL k = (i+j)/2;
        if(is_prime(k))cout<<"YESn";
        else cout<<"NOn";
    }
    return 0;
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/316755.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号