codeforces All the Vowels Please

Tom loves vowels, and he likes long words with many vowels. His favorite words are vowelly words. We say a word of length kk is vowelly if there are positive integers nn and mm such that n⋅m=kn⋅m=k and when the word is written by using nn rows and mm columns (the first row is filled first, then the second and so on, with each row filled from left to right), every vowel of the English alphabet appears at least once in every row and every column.
You are given an integer kk and you must either print a vowelly word of length kk or print −1−1 if no such word exists.
In this problem the vowels of the English alphabet are ‘a’, ‘e’, ‘i’, ‘o’ ,‘u’.
Input
Input consists of a single line containing the integer kk (1≤k≤1041≤k≤104) — the required length.
Output
The output must consist of a single line, consisting of a vowelly word of length kk consisting of lowercase English letters if it exists or −1−1 if it does not.
If there are multiple possible words, you may output any of them.
Examples
input
Copy
7
output
Copy
-1
input
Copy
36
output
Copy
agoeuioaeiruuimaeoieauoweouoiaouimae
Note
In the second example, the word “agoeuioaeiruuimaeoieauoweouoiaouimae” can be arranged into the following 6×66×6 grid:

在这里插入图片描述
It is easy to verify that every row and every column contain all the vowels.

题意:汤姆喜欢元音,他喜欢有很多元音的长单词。他最喜欢的词是元音词。如果有正整数n和m,使得n m=k,我们称长度为k的单词为元音,当用n行和m列(第一行先填,然后第二行等,每行从左到右填)书写时,英语字母表中的每个元音在每行和每列中至少出现一次。
您将得到一个整数k,如果不存在这样的单词,则必须打印长度为k的元音单词或打印−1。
在这个问题中,英语字母表中的元音是“a”、“e”、“i”、“o”、“u”。
题解:根据题意 n,m>=5,将符合条件的所有k筛选出来。
输入的k如果符合条件就构造单词并输出,否则输出-1.

#include<iostream>
#include <map>
#include<cstring>
using namespace std;


char c[]={'a','e','i','o','u'};
int prime[10005];
void ss(){
	memset(prime,0,sizeof(prime));
	for(int i=5;i*i<=10000;i++)
		{
			
				for(int j=i*i;j<=10000;j+=i)
					if(prime[j]==0)
					prime[j]=i;
			}
	
}
int main(){
	int k;
	cin>>k;
	ss();
	if(prime[k]!=0&&k/prime[k]>=5){
		for(int i=0;i<k/prime[k];i++)
			{	for(int j=i;j<prime[k]+i;j++)
					cout<<c[j%5];
				
				}
		cout<<endl;
	}
	else cout<<-1<<endl;
	return 0;
} 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

轩辕青山

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值