A - Captain Flint and Crew Recruitment
Despite his bad reputation, Captain Flint is a friendly person (at least, friendly to animals). Now Captain Flint is searching worthy sailors to join his new crew (solely for peaceful purposes). A sailor is considered as worthy if he can solve Flint's task.
Recently, out of blue Captain Flint has been interested in math and even defined a new class of integers. Let's define a positive integer [Math Processing Error]x as nearly prime if it can be represented as [Math Processing Error]p⋅q, where [Math Processing Error]1<p<q and [Math Processing Error]p and [Math Processing Error]q are prime numbers. For example, integers [Math Processing Error]6 and [Math Processing Error]10 are nearly primes (since [Math Processing Error]2⋅3=6 and [Math Processing Error]2⋅5=10), but integers [Math Processing Error]1, [Math Processing Error]3, [Math Processing Error]4, [Math Processing Error]16, [Math Processing Error]17 or [Math Processing Error]44 are not.
Captain Flint guessed an integer [Math Processing Error]n and asked you: can you represent it as the sum of [Math Processing Error]4 different positive integers where at least [Math Processing Error]3 of them should be nearly prime.
Uncle Bogdan easily solved the task and joined the crew. Can you do the same?
Input
The first line contains a single integer [Math Processing Error]t ([Math Processing Error]1≤t≤1000) — the number of test cases.
Next [Math Processing Error]t lines contain test cases — one per line. The first and only line of each test case contains the single integer [Math Processing Error]n [Math Processing Error](1≤n≤2⋅105) — the number Flint guessed.
Output
For each test case print:
- YES and [Math Processing Error]4 different positive integers such that at least [Math Processing Error]3 of them are nearly prime and their sum is equal to [Math Processing Error]n (if there are multiple answers print any of them);
- NO if there is no way to represent [Math Processing Error]n as the sum of [Math Processing Error]4 different positive integers where at least [Math Processing Error]3 of them are nearly prime.
You can print each character of YES or NO in any case.Example
7 7 23 31 36 44 100 258
NO NO YES 14 10 6 1 YES 5 6 10 15 YES 6 7 10 21 YES 2 10 33 55 YES 10 21 221 6
题意: 定义一类正整数,能够被p∗q表示,其中p、q(1<p<q)均为素数,称之为nearly primenearly prime 。现要求判断整数n,是否能被4个不同整数之和表示,
且其中至少三个整数为nearly primenearly prime (是则,输出YES
否则输出NO
)
n=31=2×7+2×5+2×3+1其中14,10,6为nearly prime
能用6,10,14,n−30表示吗?注意,当n−30=6or10or14时,出现了重复数字,我们可以构造出比{2∗3,2∗5,2∗7,n}稍大的组合,即{2∗3,2∗5,3∗5,n}
#include <cstdio> using namespace std; int main() { int t; scanf("%d", &t); while (t--) { int n; scanf("%d", &n); if (n <= 30) { printf("NO "); continue; } int last = n - 30; if (last == 6 || last == 10 || last == 14) { printf("YES 6 10 15 %d ", n - 31); } else { printf("YES 6 10 14 %d ", n - 30); } } return 0; }