Codeforces Round #660 (Div. 2)

Codeforces Round #660 (Div. 2) 传送门

A - Captain Flint and Crew Recruitment

Description

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 and p and q are prime numbers. For example, integers 6 and 10 are nearly primes (since 2⋅3=6 and 2⋅5=10), but integers 1, 3, 4, 16, 17 or 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 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) — 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⋅1e5) — the number Flint guessed.

Output

For each test case print:
YES and 4 different positive integers such that at least 3 of them are nearly prime and their sum is equal to n (if there are multiple answers print any of them);
NO if there is no way to represent n as the sum of 4 different positive integers where at least 3 of them are nearly prime.
You can print each character of YES or NO in any case.

Input

7
7
23
31
36
44
100
258

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 让我们求它是否能由4个数字组成且其中3个数是nearly prime,这4个数字不能重复

解题思路

根据题目给出的样例可以推算出能够满足由4个数字组成且其中3个数是nearly prime的最小的 n 是 31(6+10+14+1)
其中的 6 10 14 属于最小的三个 nearly prime
由于四个数字不能重复,所以我们在判断是否由6 10 14 组成时候还应该判断剩下的那个数字是否属于6 10 14中的一个
如果是的话,因为15也是nearly prime,不妨我们让14+1变成15,然后让剩下的那个数字加1,这样就避开了重复元素且保证了还有三个nearly prime (6 ,10 , 15)
如果剩下的那个数字不属于6 10 14就直接输出 n - 6 - 10 - 14即可

AC代码

#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
string ans_t = "YES";
string ans_f = "NO";
void judge(int n)
{
	if(n < 6+10+14+1){ cout<<ans_f<<endl;}
	else
	{
		cout<<ans_t<<endl;
		int tmp = n-6-10-14;
		if(tmp == 6 || tmp == 10 || tmp == 14){ cout<<"6 10 "<<14+1<<" "<<tmp-1<<endl;}
		else
		{
			cout<<"6 10 14 "<<tmp<<endl;
		}
	}
}
int main()
{
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		judge(n);
	}
	return 0;
}

B - Captain Flint and a Long Voyage

Description

Captain Flint and his crew keep heading to a savage shore of Byteland for several months already, drinking rum and telling stories. In such moments uncle Bogdan often remembers his nephew Denis. Today, he has told a story about how Denis helped him to come up with an interesting problem and asked the crew to solve it.
In the beginning, uncle Bogdan wrote on a board a positive integer x consisting of n digits. After that, he wiped out x and wrote integer k instead, which was the concatenation of binary representations of digits x consists of (without leading zeroes). For example, let x=729, then k=111101001 (since 7=111, 2=10, 9=1001).
After some time, uncle Bogdan understood that he doesn’t know what to do with k and asked Denis to help. Denis decided to wipe last n digits of k and named the new number as r.
As a result, Denis proposed to find such integer x of length n that r (as number) is maximum possible. If there are multiple valid x then Denis is interested in the minimum one.
All crew members, including captain Flint himself, easily solved the task. All, except cabin boy Kostya, who was too drunk to think straight. But what about you?
Note: in this task, we compare integers (x or k) as numbers (despite what representations they are written in), so 729<1999 or 111<1000.

Input

The first line contains a single integer t (1≤t≤1000) — the number of test cases.
Next t lines contain test cases — one per test case. The one and only line of each test case contains the single integer n (1≤n≤105) — the length of the integer x you need to find.
It’s guaranteed that the sum of n from all test cases doesn’t exceed 2⋅105.

Output

For each test case, print the minimum integer x of length n such that obtained by Denis number r is maximum possible.

Input

2
1
3

Output

8
998

Note

In the second test case (with n=3), if uncle Bogdan had x=998 then k=100110011000. Denis (by wiping last n=3 digits) will obtain r=100110011.
It can be proved that the 100110011 is the maximum possible r Denis can obtain and 998 is the minimum x to obtain it.


解题思路

删除的位置选取 8(1000)
不删除的位置直接选取最大的 9 (1001)
如果n%4不为0的话,说明溢出4位二进制数,一个8不够删,要补一个8


AC代码

#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		if(n == 1)
		{
			cout<<"8"<<endl;
		}else
		{
			int n8 = n/4;
			if(n % 4 == 0)
			{
				n8 = n8;
			}else
			{
				n8++;
			}
			int n9 = n - n8;
			for(int i = 0 ; i < n9 ; i++)
			{
				cout<<"9";
			}
			for(int i = 0 ; i < n8 ; i++)
			{
				cout<<"8";
			}
			cout<<endl;
		}
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值