#P5440. 【XR-2】奇迹

    ID: 4376 远端评测题 4000ms 500MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>搜索O2优化剪枝素数判断,质数,筛法

【XR-2】奇迹

Description

We define a date as an 8-digit number. Digits 141 \sim 4 form the year, digits 565 \sim 6 form the month, and digits 787 \sim 8 form the day. If a part has fewer digits, it is padded with 00. Also, the day represented by the date must really exist, and the year ranges from 199991 \sim 9999.

All miracle dates share the same property: the 2-digit number formed by the “day”, the 4-digit number formed by “month + day”, and the 8-digit number formed by “year + month + day” are all prime numbers. However, not every date with this property will necessarily have a miracle.

Now you are given a date that may have a miracle, but unfortunately this date is incomplete: among the 8 digits, some digits may be unknown. You need to determine how many possible dates it could be, so that you can be fully prepared to welcome the miracle.

Input Format

This problem has multiple test cases.

The first line contains a positive integer TT, the number of test cases.

The next TT lines each contain an 8-character string. If the ii-th character is -, it means the ii-th digit of the date is unknown; otherwise, it means the ii-th digit of the date is the digit at position ii in the string.

Output Format

For each test case, output one integer per line, representing the answer.

2
53-7-3-7
20190629

6
0

Hint

[Sample 11 Explanation]

The 6 possible dates for 53-7-3-7 are:

53070307
53070317
53170307
53370307
53570317
53770307

[Constraints]

There are 1010 test points in total. Let cc be the number of - characters in the 8-character string.

For the first 99 test points, in the ii-th test point it is guaranteed that c=i1c = i - 1.

For 100%100\% of the testdata, it is guaranteed that 1T101 \le T \le 10.

Translated by ChatGPT 5