hpu 1410: QAQ & 火星情报局(哥德巴赫猜想定理)

题目传送门

哥德巴赫猜想传送

利用了哥德巴赫的两个定理

任何一个大于2的偶数都可以写成两个素数之和,
任何一个大于5的整数都可以写成三个素数之和。

以及一个推论

存在大于5的整数可以写为2和一个素数之和(这是推论)

代码如下

#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>

typedef long long ll;
typedef unsigned long long ull;
using namespace std;
bool isprime(ll n){
    if(n < 2)   return false;
    for(ll i=2;i*i<=n;i++){
        if(n % i == 0)  return false;
    }
    return true;
}
int solve(ll n){
    if(isprime(n))  return 1;
    else if((n % 2 == 0) || isprime(n-2))   return 2;
    else    return 3;
}
int main(void){
    int t;
    ll n;
    scanf("%d",&t);
    while(t--) {
        scanf("%lld",&n);
        printf("%d\n",solve(n));
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值