CF123A.Prime Permutation
普及-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a string s, consisting of small Latin letters. Let's denote the length of the string as |s|. The characters in the string are numbered starting from 1.
Your task is to find out if it is possible to rearrange characters in string s so that for any prime number p ≤ |s| and for any integer i ranging from 1 to |s| / p (inclusive) the following condition was fulfilled s__p = s__p × i. If the answer is positive, find one way to rearrange the characters.
给你一个由小写拉丁字母组成的字符串 s。记该字符串的长度为 ∣s∣。字符串中的字符编号从 1 开始。
你的任务是判断:能否重新排列字符串 s 中的字符,使得对任意素数 p≤∣s∣ 以及任意整数 i(满足 1≤i≤∣s∣/p),均满足条件 sp=sp×i?若存在这样的重排方式,请给出其中一种。
输入格式
The only line contains the initial string s, consisting of small Latin letters (1 ≤ |s| ≤ 1000).
仅一行,包含初始字符串 s,由小写拉丁字母组成(1 ≤ ∣s∣ ≤ 1000)。
输出格式
If it is possible to rearrange the characters in the string so that the above-mentioned conditions were fulfilled, then print in the first line "YES" (without the quotes) and print on the second line one of the possible resulting strings. If such permutation is impossible to perform, then print the single string "NO".
如果可以重新排列字符串中的字符,使得上述条件得到满足,则在第一行输出 "YES"(不带引号),并在第二行输出一个可能的满足条件的结果字符串。如果无法进行这样的排列,则仅输出字符串 "NO"。
输入输出样例
输入#1
abc
输出#1
YES abc
输入#2
abcd
输出#2
NO
输入#3
xxxyxxx
输出#3
YES xxxxxxy
说明/提示
In the first sample any of the six possible strings will do: "abc", "acb", "bac", "bca", "cab" or "cba".
In the second sample no letter permutation will satisfy the condition at p = 2 (_s_2 = _s_4).
In the third test any string where character "y" doesn't occupy positions 2, 3, 4, 6 will be valid.
在第一个样例中,以下六种可能的字符串中的任意一个都满足要求:“abc”、“acb”、“bac”、“bca”、“cab”或“cba”。
在第二个样例中,不存在任何字母排列能满足在 p=2 处的条件(即 s2=s4)。
在第三个测试用例中,任意一个字符 “y” 不出现在位置 2、3、4、6 的字符串均为合法解。
输入解题思路,AI测评打分。不知道怎么写?