AT_abc475_d.Alphametic Prime

普及-

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a string SS consisting of lowercase English letters. If there exists a prime number PP satisfying the following condition, find one such PP.

Condition: Let TT be the string representing PP in decimal notation without an extra leading 0. Then, ∣S∣=∣T∣|S|=|T|, and for every 1≤i<j≤∣S∣1\leq i< j \leq |S|, we have Si=SjS_i=S_j if and only if Ti=TjT_i=T_j.

给你一个由小写英文字母组成的字符串 SS。如果存在一个满足以下条件的质数 PP,请找出一个这样的 PP。

条件:设 TT 为 PP 在十进制表示下(不含前导零)所对应的字符串。则需满足 ∣S∣=∣T∣|S|=|T|,且对任意 1≤i<j≤∣S∣1\leq i< j \leq |S|,均有 Si=SjS_i=S_j 当且仅当 Ti=TjT_i=T_j。

输入格式

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

SS

输入从标准输入中以如下格式给出:

SS

输出格式

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。
如果存在,输出任意一个满足条件的素数。若存在多个解,输出其中任意一个即可。

输入输出样例

  • 输入#1

    motor

    输出#1

    10607
  • 输入#2

    byebye

    输出#2

    -1
  • 输入#3

    coconut

    输出#3

    1010237

说明/提示

Sample 1 Explanation:
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 2 Explanation:
If there is no prime number satisfying the condition, output -1.

Constraints

  • SS is a string of length between 11 and 77 (inclusive) consisting of lowercase English letters.

样例 1 解释:
除此之外,例如输出 40709 也是可接受的。然而,例如 81817 不满足条件,因此不可接受。

样例 2 解释:
若不存在满足条件的素数,则输出 -1。

限制条件

  • SS 是一个由小写英文字母组成的字符串,其长度在 11 到 77(含)之间。

输入解题思路,AI测评打分。不知道怎么写?

首页