Supreme Number

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 N as the supreme number if and only if each number made up of an non-empty subsequence of all the numeric digits of N must be either a prime number or 11.

For example, 17 is a supreme number because 1, 7, 17 are all prime numbers or 1, and 19 is not, because 9 is not a prime number.

Now you are given an integer  (2≤N≤10100), could you find the maximal supreme number that does not exceed N?

Input

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

In the following TT lines, there is an integer N (2≤N≤10^100).

Output

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

样例输入

2
6
100

样例输出

Case #1: 5
Case #2: 73

题目来源

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

题意

定义supreme number:一个数是素数,这个数的每一项都是1或素数,并且由这个数的每一位数组成的序列中,取出组成的任意子序列组成一个数,都是素数

求小于等于N的最大的supreme number

思路

打表找规律吧。。。最后会发现只有20个数符合supreme number的定义,然后把这20的数存入数组,输入整数N,在数组中查找符合要求的数就可以了

AC代码

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <limits.h>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <string>
#define ll long long
#define ull unsigned long long
#define ms(a) memset(a,0,sizeof(a))
#define pi acos(-1.0)
#define INF 0x7f7f7f7f
#define lson o<<1
#define rson o<<1|1
const double E=exp(1);
const int maxn=1e6+10;
const int mod=1e9+7;
using namespace std;
int vis[30]={1,2,3,5,7,11,13,17,23,31,37,53,71,73,113,131,137,173,311,317};
char num[maxn];
int main(int argc, char const *argv[])
{
ios::sync_with_stdio(false);
int t;
cin>>t;
int _=0;
while(t--)
{
int ans=0;
cin>>num;
int l=strlen(num);
cout<<"Case #"<<++_<<": ";
if(l>3)
cout<<317<<endl;
else
{
ans=0;
int res=10;
for(int i=0;i<l;i++)
ans=ans*res+num[i]-'0';
if(ans>=317)
cout<<317<<endl;
else
{
for(int i=0;i<21;i++)
if(vis[i]<=ans&&vis[i+1]>ans)
cout<<vis[i]<<endl;
}
}
}
return 0;
}

ACM-ICPC 2018 沈阳赛区网络预赛-K:Supreme Number的更多相关文章

  1. ACM-ICPC 2018 沈阳赛区网络预赛 K Supreme Number(规律)

    https://nanti.jisuanke.com/t/31452 题意 给出一个n (2 ≤ N ≤ 10100 ),找到最接近且小于n的一个数,这个数需要满足每位上的数字构成的集合的每个非空子集 ...

  2. ACM-ICPC 2018 沈阳赛区网络预赛 K. Supreme Number

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

  3. ACM-ICPC 2018 沈阳赛区网络预赛 K题

    题目链接: https://nanti.jisuanke.com/t/31452 AC代码(看到不好推的定理就先打表!!!!): #include<bits/stdc++.h> using ...

  4. 【ACM-ICPC 2018 沈阳赛区网络预赛 K】Supreme Number

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 显然每个数字只可能是1,3,5,7 然后如果3,5,7这些数字出现两次以上.显然两个3||5||7都能被11整除. 然后1的话最多能 ...

  5. ACM-ICPC 2018 沈阳赛区网络预赛-D:Made In Heaven(K短路+A*模板)

    Made In Heaven One day in the jail, F·F invites Jolyne Kujo (JOJO in brief) to play tennis with her. ...

  6. 图上两点之间的第k最短路径的长度 ACM-ICPC 2018 沈阳赛区网络预赛 D. Made In Heaven

    131072K   One day in the jail, F·F invites Jolyne Kujo (JOJO in brief) to play tennis with her. Howe ...

  7. ACM-ICPC 2018 沈阳赛区网络预赛 F. Fantastic Graph

    "Oh, There is a bipartite graph.""Make it Fantastic." X wants to check whether a ...

  8. ACM-ICPC 2018 沈阳赛区网络预赛 J树分块

    J. Ka Chang Given a rooted tree ( the root is node 11 ) of NN nodes. Initially, each node has zero p ...

  9. ACM-ICPC 2018 焦作赛区网络预赛 K题 Transport Ship

    There are NN different kinds of transport ships on the port. The i^{th}ith kind of ship can carry th ...

随机推荐

  1. 服务消费和负载(Ribbon)

    使用RestTemplate调用服务 在上一篇教程中,我们是这样调用服务的,先通过 LoadBalancerClient 选取出对应的服务,然后使用 RestTemplate 进行远程调用. Load ...

  2. 如何快速成为一名Linux运维工程师

    如今的互联网,绝大多数的网站.服务.游戏均是跑在Linux上面的,虽说Linux发行版众多,只要玩熟了一种发行版,了解了Linux精髓.基本架构.设计原理,其他都是触类旁通的,千万不要在选择哪一发行版 ...

  3. Linux系统默默改变了人类世界的生活方式

    你知道操作系统都有些什么吗?Windows啊.这是我在上大学之前的问答,我当时认为只一种叫做Windows的操作系统,可是我错了,当我上大学以后,作为计算机专业的一名学生的时候我第一次接触到了除Win ...

  4. leetcode python 001

    给定一个数组,和一个数字target,要求返回和为target的两个数组成员的下标. import numpy as npimport time #### 构造题目 , x数组大小x=100000l1 ...

  5. C++基础知识:动态类型识别

    1.动态类型指的是基类指针所指向的对象的实际类型 2.C++中的多态根据实际的对象类型调用对应的虚函数(1)可以在基类中定义虚函数返回具体的类型信息(2)所有的派生类都必须实现类型相关的虚函数(3)每 ...

  6. 深入理解java虚拟机---Class文件(二十)

    无符号数.表 当实现了不同语言的编译器,比如jython,jruby等等,那么就可以利用这些语言编写代码,通过各自的编译器编译成符合jvm规范的字节码文件,就可以利用jvm来执行了. Class文件在 ...

  7. Linux文件管理常用命令用法总结

    1.touch change file timestamps. 命令用于修改文件或者目录的时间属性,包括存取时间和更改时间.若文件不存在,系统会建立一个新的文件.stat,ls -l 可以显示档案的时 ...

  8. bootstrapTable--4.删除和批量删除

    http://blog.csdn.net/qq_26553781/article/details/78058389 ------------------------------------------ ...

  9. LeetCode 43 字符串相乘

    题目: 给定两个以字符串形式表示的非负整数 num1 和 num2,返回 num1 和 num2 的乘积,它们的乘积也表示为字符串形式. 示例 1: 输入: num1 = "2", ...

  10. springboot学习章节代码-spring高级话题

    1.Spring Aware(获取Spring容器的服务) hi, i am guodaxia! test.txt package com.zhen.highlights_spring4.ch3.aw ...