CodeForces1388A - Captain Flint and Crew Recruitment

题意

对于一个数 x x x,如果它可以表示成 x = p × q x=p\times q x=p×q,称之为近似质数,其中 1 < p < q 1<p<q 1<p<q,且 p , q p,q p,q都为质数。现在给你一个n,请问是否能将这个n分成4个不同的正整数,其中至少3个为近似质数

题解

至少三个近似质数,那我们就先算出来最小的三个近似质数,分别为 6 = 2 × 3 , 10 = 2 × 5 , 14 = 2 × 7 6=2\times 3,10=2\times 5,14=2\times 7 6=2×3,10=2×5,14=2×7,只要 n > 6 + 10 + 14 n>6+10+14 n>6+10+14,那么它必然可以拆成 6 , 10 , 14 , n − 6 − 10 − 14 6,10,14,n-6-10-14 6,10,14,n61014,就是符合题意的,所以 n < = 30 n<=30 n<=30直接输出“NO”即可。但是这个时候注意要求不同的正整数,那么也就是要求 n − 30 ≠ 6 , n − 30 ≠ 10 , n − 30 ≠ 14 n-30\neq6,n-30\neq10,n-30\neq14 n30=6,n30=10,n30=14。那么出现这种情况怎么办呢?第四大的近似质数 15 = 3 × 5 15=3\times 5 15=3×5,只比14大1。那么出现相等的时候我们就可以将14替换成15,这样 n − 31 n-31 n31必然不会再等于6,10,15。

AC代码

#include <bits/stdc++.h>
#define pb push_back 
#define fir first
#define sec second
#define ms(a,b) memset(a,b,sizeof(a)) 
#define INF 0x3f3f3f3f
#define sp system("pause")
#define multi int t;cin>>t;while(t--) 
using namespace std;
typedef long long ll;
typedef double db;
const int N=2e5+5;
const int mod=10007;
const db pi=acos(-1.0);
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("D:\\work\\data.in","r",stdin);
    #endif
    int a=6,b=10,c=14,d=15;
    multi{
        int n;
        cin>>n;
        if(n<=a+b+c) cout<<"NO"<<endl;
        else {
            cout<<"YES"<<endl;
            int rest=n-a-b-c;
            if(rest==a||rest==b||rest==c){
                cout<<a<<" "<<b<<" "<<d<<" "<<n-a-b-d<<endl;
            }
            else cout<<a<<" "<<b<<" "<<c<<" "<<n-a-b-c<<endl;
        }


    }
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值