第 475 场 AtCoder Beginner Contest
D
字母算术素数
Alphametic Prime
AtCoder
⌀ 741
原题
← CE →

字母算术素数AI (CI翻译)

Problem Statement

题目描述

AI (CI翻译)

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$.

给定一个由小写英文字母组成的字符串 $S$。如果存在满足以下条件的素数 $P$,请找出其中任意一个。AI (CI翻译)

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$.

条件:令 $T$ 表示 $P$ 的十进制表示,且不含额外的前导 0。则 $|S|=|T|$,并且对于任意 $1\leq i< j \leq |S|$,当且仅当 $S_i=S_j$ 时,有 $T_i=T_j$。AI (CI翻译)

Constraints

约束条件

AI (CI翻译)
  • $S$ is a string of length between $1$ and $7$ (inclusive) consisting of lowercase English letters.
  • $S$ 是一个长度在 $1$ 到 $7$(含)之间、由小写英文字母组成的字符串。
AI (CI翻译)

Input

输入格式

AI (CI翻译)

The input is given from Standard Input in the following format:

输入从标准输入按以下格式给出:AI (CI翻译)

S

S
AI (CI翻译)

Output

输出格式

AI (CI翻译)

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.

如果不存在满足题目描述中条件的素数,输出 -1。 如果存在这样的素数,输出其中任意一个。如果有多个答案,输出其中任意一个都将被接受。AI (CI翻译)

样例

Input #1
motor
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.
Input #2
byebye
Output #2
-1
If there is no prime number satisfying the condition, output `-1`.
Input #3
coconut
Output #3
1010237
题目信息
题号
abc475_d
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。