ACM-ICPC 2018 沈阳赛区网络预赛

Supreme Number


  • 1000ms
  • 131072K
 

A prime number (or a prime) is a natural number greater than 111 that cannot be formed by multiplying two smaller natural numbers.

Now lets define a number NNN as the supreme number if and only if each number made up of an non-empty subsequence of all the numeric digits of NNN must be either a prime number or 111.

For example, 171717 is a supreme number because 111, 777, 171717 are all prime numbers or 111, and 191919 is not, because 999 is not a prime number.

Now you are given an integer N (2≤N≤10100)N (2 leq N leq 10^{100})N (2N10100), could you find the maximal supreme number that does not exceed NNN?

Input

In the first line, there is an integer T (T≤100000)T (T leq 100000)T (T100000) indicating the numbers of test cases.

In the following TTT lines, there is an integer N (2≤N≤10100)N (2 leq N leq 10^{100})N (2N10100).

Output

For each test case print "Case #x: y", in which xxx is the order number of the test case and yyy is the answer.

样例输入

2
6
100

样例输出

Case #1: 5
Case #2: 73
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int main()
 4 {
 5     int a[20] = {1,2,3,5,7,11,13,17,23,31,37,53,71,73,113,131,137,173,311,317
 6                 };
 7     int s;
 8     int t,count = 1;
 9     cin >> t;
10     while(t--)
11     {
12         cin >> s;
13         cout << "Case #" << count++ << ": " ;
14         if(s >= 317)
15         {
16             cout << a[19] << endl;
17             continue;
18         }
19         else
20         {
21             for(int i = 19; i >= 0; i --)
22             {
23                 if(s >= a[i])
24                 {
25                     cout << a[i] << endl;
26                     break;
27                 }
28             }
29         }
30     }
31     return 0;
32 }
原文地址:https://www.cnblogs.com/weixq351/p/9660345.html