Supreme Number(找规律,打表)

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 (2≤N≤10100), 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 (T≤100000) 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 (2≤N≤10100).

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

题目来源

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

题意:找到N以内最大的supreme number:此数为1或素数,且该数的子序列也是1或素数(不按顺序,随机重组);

可以发现1位数有:1,2,3,5,7;2位数有:11,13,17,23,31,37,53,71,73;3位数有:113,131,137,173,311,317;

代码如下:

#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int a[20] = {1,2,3,5,7,11,13,17,23,31,37,53,71,73,113,131,137,173,311,317};
    int s;
    int t,count = 1;
    cin >> t;
    while(t--)
    {
        cin >> s;
        cout << "Case #" << count++ << ": " ;
        if(s >= 317)
        {
            cout << a[19] << endl;
            continue;
        }
        else
        {
            for(int i = 19;i >= 0;i --)
             {
                 if(s >= a[i])
                 {
                     cout << a[i] << endl;
                     break;
                 }
             }
        }
    }
    return 0;
}

刚开始我错了很多次的代码是这样的:

#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int a[20] = {1,2,3,5,7,
    11,13,17,23,31,37,53,71,73,
    113,131,137,173,311,317};
    int s;
    int t,count = 1;
    cin >> t;
    while(t--)
    {
        cin >> s;
        cout << "Case #" << count++ << ": " ;
        if(s >= 317)
        {
            cout << a[19] << endl;
            continue;
        }
        else
        {
            for(int i = 19;i >= 0;i --)
             {
                 if(s >= a[i])
                 {
                     cout << a[i] << endl;
                     break;
                 }
             }
        }
    }
    return 0;
}

在数组里加了不必要的换行;。。。。。。。。

我用的是codeblocks,可以正常运行,提交的时候就不对了。。。。。

还是基础不行啊。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值