Codeforces #660 (Div. 2) A

A. Captain Flint and Crew Recruitment

time limit per test:1 second
memory limit per test:256 megabytes
input:standard input
output:standard output

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 x as nearly prime if it can be represented as p⋅q, where 1 < p < q 1<p<q 1<p<q and p p p and q q q are prime numbers. For example, integers 6 6 6 and 10 10 10 are nearly primes ( ( (since 2 ⋅ 3 = 6 2⋅3=6 23=6 and 2 ⋅ 5 = 10 ) 2⋅5=10) 25=10), but integers 1 , 3 , 4 , 16 , 17 1, 3, 4, 16, 17 1,3,4,16,17 or 44 44 44 are not.

Captain Flint guessed an integer n and asked you: can you represent it as the sum of 4 different positive integers where at least 3 3 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 t ( 1 ≤ t ≤ 1000 ) (1≤t≤1000) (1t1000) — the number of test cases.

Next t lines contain test cases — one per line. The first and only line of each test case contains the single integer n ( 1 ≤ n ≤ 2 ⋅ 1 0 5 ) (1≤n≤2⋅10^5) (1n2105)— the number Flint guessed.

Output

For each test case print:

  • YES and 4 4 4 d i f f e r e n t different different positive integers such that at least 3 3 3 of them are nearly prime and their sum is equal to n n n (if there are multiple answers print any of them);
  • NO if there is no way to represent n n n as the sum of 4 4 4 d i f f e r e n t different different p o s i t i v e positive positive integers where at least 3 3 3 of them are nearly prime.

You can print each character of Y E S YES YES or N O NO NO in any case.

Example

i n p u t input input

7
7
23
31
36
44
100
258

O u t p u t Output Output

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

N o t e Note Note
In the first and second test cases, it can be proven that there are no four different positive integers such that at least three of them are nearly prime.

In the third test case, n = 31 = 2 ⋅ 7 + 2 ⋅ 5 + 2 ⋅ 3 + 1 : n=31=2⋅7+2⋅5+2⋅3+1: n=31=27+25+23+1: integers 14 , 10 , 6 14, 10, 6 14,10,6 are nearly prime.

In the fourth test case, n = 36 = 5 + 2 ⋅ 3 + 2 ⋅ 5 + 3 ⋅ 5 : n=36=5+2⋅3+2⋅5+3⋅5: n=36=5+23+25+35: integers 6 , 10 , 15 6, 10, 15 6,10,15 are nearly prime.

In the fifth test case, n = 44 = 2 ⋅ 3 + 7 + 2 ⋅ 5 + 3 ⋅ 7 : n=44=2⋅3+7+2⋅5+3⋅7: n=44=23+7+25+37: integers 6 , 10 , 21 6, 10, 21 6,10,21 are nearly prime.

In the sixth test case, n = 100 = 2 + 2 ⋅ 5 + 3 ⋅ 11 + 5 ⋅ 11 : n=100=2+2⋅5+3⋅11+5⋅11: n=100=2+25+311+511: integers 10 , 33 , 55 10, 33, 55 10,33,55 are nearly prime.

In the seventh test case, n = 258 = 2 ⋅ 5 + 3 ⋅ 7 + 13 ⋅ 17 + 2 ⋅ 3 : n=258=2⋅5+3⋅7+13⋅17+2⋅3: n=258=25+37+1317+23: integers 10 , 21 , 221 , 6 10, 21, 221, 6 10,21,221,6 are nearly prime.

题意及题解:

根据题意,我们可以得到:nearly prime(下文称近质数)
质数: 2 、 3 、 5 、 7 … … 2、3、5、7…… 2357
2 × 3 = 6 2×3=6 2×3=6 3 × 5 = 15 3×5=15 3×5=15 5 × 7 = 35 5×7=35 5×7=35
2 × 5 = 10 2×5=10 2×5=10 3 × 7 = 21 3×7=21 3×7=21
2 × 7 = 14 2×7=14 2×7=14
则nearly prime(近质数)从小到大依次为 6 、 10 、 14 、 15 … … 6、10、14、15…… 6101415
题目要求输入一个 n n n,要求满足有 4 4 4个数之和(其中 3 3 3个数为nearly prime)为 n n n,那么我们依次取nearly prime 从小到大3个分别为 6 、 10 、 14 6、10、14 61014。所以, n n n至少要大于 30 = 6 + 10 + 14 30=6+10+14 30=6+10+14,才能满足题意输出 Y E S YES YES
n ≤ 30 n ≤ 30 n30时,输出 N O NO NO
n > 30 n>30 n30时,题目要求 4 4 4个数不能重复,所以不能存在, 6 6 6 6 6 6 10 10 10 14 14 14 6 6 6 10 10 10 10 10 10 14 14 14 6 6 6 10 10 10 14 14 14 14 14 14,这 3 3 3种情况。所以需要把这三种情况单独列出来,也就是 n = 36 , 40 , 44 n = 36,40,44 n=364044时。
此时可以通过用 15 15 15 ( 15 (15 15也是nealy prime ) ) 代替 14 14 14来改变前三个数的总和,达成 4 4 4个数不相同的目的。
分析完毕 —— 上代码:

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
typedef long long ll;
using namespace std;
int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        //nearly prime 从小到大分别是6、10、14、15、21......
        //(前三个数取尽可能小,最后一个数无所谓)
        if (n <= 30)
        {
            printf("NO\n"); //所以n至少要大于30 = 6+10+14,才有可能是YES
            continue;
        }
        else
        {
            printf("YES\n");
            //要求四个数不相同所以当有2个6,或者2个10,或者2个14的时候不满足
            //此时可以通过用15替代14来改变前三个数的总和。
            if (n == 36 || n == 40 || n == 44)
                printf("6 10 15 %d\n", n - 31);//第4个数是n减去前三个数的总和
            else
                printf("6 10 14 %d\n", n - 30);//第4个数是n减去前三个数的总和
            //如果需要跟题目给出例子一样输出:可以将if的条件改成如下:
            /*
            if (n == 36)
                printf("5 6 10 15\n");
            else if (n == 40)
                printf("6 10 15 9\n");
            else if (n == 44)
                printf("6 7 10 21\n");
            else
                printf("6 10 14 %d\n", n - 30);
            */
        }
    }
	return 0;
}
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值