D. 字母算式素数 / Alphametic Prime

    传统题 2000ms 256MiB

字母算式素数 / Alphametic Prime

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

Problem Statement

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.

Constraints

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

Input

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

  • SS

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.

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

byebye
-1

If there is no prime number satisfying the condition, output -1.

coconut
1010237

ABC475 赛后模拟赛 ✅

未参加
状态
已结束
规则
IOI
题目
7
开始于
2026-9-12 21:40
结束于
2026-9-26 21:40
持续时间
336 小时
主持人
参赛人数
59