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 (2≤N≤10100), 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 (T≤100000) indicating the numbers of test cases.

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

Output

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

样例输入复制

2
6
100

样例输出复制

Case #1: 5
Case #2: 73
#include <iostream>
#include <sstream>
#define ll long long
using namespace std;
int a[20]={317, 311,173,137,131,113,73,71,53,37,31,23,17,13,11,7,5,3,2,1};
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0); int T;
cin>>T;
for(int t=1;t<=T;t++)
{
int aa;
stringstream aaa;
string s;
cin>>s;
aaa<<s;
aaa>>aa;
int len=s.length();
if(len>=4||aa>317) {
cout<<"Case #"<<t<<": "<<a[0]<<endl;
continue;
}
if(aa==317) {
cout<<"Case #"<<t<<": "<<"317"<<endl;continue;
}
for(int i=1;i<20;i++)
{
if(aa<a[i-1]&&aa>=a[i])
{
cout<<"Case #"<<t<<": "<<a[i]<<endl;
break;
}
}
}
return 0;
}

这个题的题意,说的是给你一个大于等于2,且小于等于10的100次方,要你求的是,小于这个数,但是这个数要是素数,而且这个数里面任意x个数的组合也要是素数的数,x个数可以不连续。

首先输入很大, 所以使用了string类,读入一个字符串,然后用了stringstream,避免缓存溢出。因为将字符串转换为整数的方式可以用stdio里面的sprintf转换,但是由于数字太大,所以就换用stringstream这个字符串流。

然后就是枚举所有的是素数,而且每一位都是素数,且任何几位的组合都是素数的数,总共也就二十个,应该是吧,请读者自行验证之。

然后就是最上面的ios_base::sync_with_stdio(flase)解除绑定的,和cin.tie(0)都是加快cin的速度的。

Supreme Number的更多相关文章

  1. 计蒜客31452 Supreme Number(找规律)

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

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

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

  3. 计蒜客 31452 - Supreme Number - [简单数学][2018ICPC沈阳网络预赛K题]

    题目链接:https://nanti.jisuanke.com/t/31452 A prime number (or a prime) is a natural number greater than ...

  4. 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 ...

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

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

  6. upc组队赛15 Supreme Number【打表】

    Supreme Number 题目链接 题目描述 A prime number (or a prime) is a natural number greater than 1 that cannot ...

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

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

  8. 2018 ICPC 沈阳网络赛预赛 Supreme Number(找规律)

    [传送门]https://nanti.jisuanke.com/t/31452 [题目大意]:给定一个数字(最大可达10100),现在要求不超过它的最大超级质数.超级质数定义:对于一个数,把它看成数字 ...

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

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

随机推荐

  1. hdoj5327【前缀和思想】

    题意: 找给定区间的美丽数,美丽数的意思就是这个数每个位上的数都是唯一的. 思路: 前缀和的思想. 感想: 就是你当前位置代表某个特性的前面的所有和(瞎比比的,说了下感觉).前提是你必须找到这样的特性 ...

  2. vbox虚拟机配置Redhat6.4本地yum源

    作为一个新手,配置这个yum源配了4天,遇到了各种问题,也按照网络上面一些方法在163上面下载CentOS6的yum源来替换Redhat本地的yum源,但是配置过程中,出现很多错误,发现直接在本地配置 ...

  3. Oracle数据库创建表空间及用户授权

    /*分为四步 */ /*第1步:创建临时表空间 */ create temporary tablespace test_temp tempfile 'E:\app\Administrator\orad ...

  4. 有哪些值得学习的spring boot开源项目?

    1. awesome-spring-boot 首先给大家介绍的就是Spring Boot 中文索引,这是一个专门收集 Spring Boot 相关资料的开源项目,也有对应的导航页面. 产品主页 htt ...

  5. linux添加开机启动脚本

    [root@mysql ~]# ll /etc/rc.local lrwxrwxrwx. 1 root root 13 Mar 12 22:20 /etc/rc.local -> rc.d/rc ...

  6. Hacker的社交礼仪与自我修养【转】

    Hacker School是位于纽约的一所特殊的编程“学校”,他们的目标是帮助参与者变成“更好的程序员”,之所以说他们特殊是因为这所“学校”没有老师,没有考试,也不会颁发证书,他们信奉三人行必有我师, ...

  7. 外文翻译 《How we decide》被情感愚弄 第三节

    本科论文答辩终于结束啦,一切都要继续回到正轨. 这是第三章章最后一节 书的导言 本章第二节 本章第一节 "信用卡是我的敌人."Herman Palmer这样说到.在平日,Herma ...

  8. 浅议block实现原理,block为什么使用copy关键字?

    1.block是一个特殊的oc对象,建立在栈上,而不是堆上,这么做一个是为性能考虑,还有就是方便访问局部变量. 2.默认Block使用到的局部变量会被copy,而不是retain.所以,他无法改变局部 ...

  9. Java关键字-volatile

    关键字volatile可以说是Java虚拟机提供的最轻量级的同步机制. 一旦某个共享变量(类的成员变量.类的静态成员变量)被volatile修饰之后,那么就具备了两层语义: 1.保证了不同线程对这个变 ...

  10. 各 Android 平台版本支持的 API 级别

    平台版本 API 级别 VERSION_CODE 备注 Android 7.0 24 N 平台亮点 Android 6.0 23 M 平台亮点 Android 5.1 22 LOLLIPOP_MR1 ...