题意
对于一个数 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,n−6−10−14,就是符合题意的,所以 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 n−30=6,n−30=10,n−30=14。那么出现这种情况怎么办呢?第四大的近似质数是 15 = 3 × 5 15=3\times 5 15=3×5,只比14大1。那么出现相等的时候我们就可以将14替换成15,这样 n − 31 n-31 n−31必然不会再等于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;
}
}
}