/
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
英小文字からなる文字列 S が与えられます。以下の条件を満たす素数 P が存在するなら 1 つ求めてください。
条件: P を先頭に余分な 0 をつけない十進表記で表した文字列を T とする。|S|=|T| かつ、全ての 1\leq i< j \leq |S| に対し、S_i=S_j と T_i=T_j が同値である。
制約
- S は英小文字のみからなる長さ 1 以上 7 以下の文字列
入力
入力は以下の形式で標準入力から与えられる。
S
出力
問題文中の条件を満たす素数が存在しないとき -1 と出力せよ。
存在するとき、そのような素数を 1 つ出力せよ。答えが複数ある場合、どれを出力しても正解とみなされる。
入力例 1
motor
出力例 1
10607
この他、例えば 40709 などの出力でも正解とみなされます。また、例えば 81817 は条件を満たさないため不正解となります。
入力例 2
byebye
出力例 2
-1
条件を満たす素数が存在しないときは -1 と出力してください。
入力例 3
coconut
出力例 3
1010237
Score : 400 points
Problem Statement
You are given a string S consisting of lowercase English letters. If there exists a prime number P satisfying the following condition, find one such P.
Condition: Let T be the string representing P in decimal notation without an extra leading 0. Then, |S|=|T|, and for every 1\leq i< j \leq |S|, we have S_i=S_j if and only if T_i=T_j.
Constraints
- S is a string of length between 1 and 7 (inclusive) consisting of lowercase English letters.
Input
The input is given from Standard Input in the following format:
S
Output
If there is no prime number satisfying the condition in the problem statement, output -1.
If one exists, output one such prime number. If there are multiple solutions, any of them will be accepted.
Sample Input 1
motor
Sample Output 1
10607
Besides this, for example, outputting 40709 would also be accepted. However, for example, 81817 does not satisfy the condition, so it would not be accepted.
Sample Input 2
byebye
Sample Output 2
-1
If there is no prime number satisfying the condition, output -1.
Sample Input 3
coconut
Sample Output 3
1010237