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;
}