Supreme Number 2018沈阳icpc网络赛 找规律

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

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

For example, 1717 is a supreme number because 11, 77, 1717 are all prime numbers or 11, and 1919 is not, because 99 is not a prime number.

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

Input

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

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

Output

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

样例输入复制
2
6
100
样例输出复制
Case #1: 5
Case #2: 73
题目来源

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

 

题意:一个supreme数是其的所有子集都是质数或者1(可以是不连续的子集),求小于n的最大的supreme数

分析:考虑单独的一个数是supreme数或1的有1,2,3,5,7,二位数是supreme数的有73,71,53,37,31,23,17,13,11,三位数是supreme数的有317,311,173,137,131,113,四位数没有supreme数

所以我们直接用个数组保存下来这些supreme数,然后看输入的数处于哪个范围就行

AC代码:

#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#define ls (r<<1)
#define rs (r<<1|1)
#define debug(a) cout << #a << " " << a << endl
using namespace std;
typedef long long ll;
const ll maxn = 1e5+10;
const ll mod = 1e9+7;
const double pi = acos(-1.0);
const double eps = 1e-8;
ll prime[] = {317,311,173,137,131,113,73,71,53,37,31,23,17,13,11,7,5,3,2,1};
int main() {
    ll T;
    cin >> T;
    for( ll cas = 1; cas <= T; cas ++ ) {
        string s;
        cin >> s;
        cout << "Case #" << cas << ": ";
        if( s.length() >= 4 ) {
            cout << 317 << endl;
        } else {
            ll sum = 0;
            for( ll i = 0; i < s.length(); i ++ ) {
                sum = sum*10 + (s[i]-'0');
            }
            for( ll i = 0; i < 20; i ++ ) {
                if( sum >= prime[i] ) {
                    cout << prime[i] << endl;
                    break;
                }
            }
        }
    }
    return 0;
}

  

转载于:https://www.cnblogs.com/l609929321/p/9614891.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值