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. 洛谷 - P2181 - 对角线 - 打表 - 组合数学

    https://www.luogu.org/problemnew/show/P2181 对于某条对角线,除去从两端出发的对角线,其他的都与它有1个交点. 每个点有(n-3)条对角线,每条对角线和其余C ...

  2. LuoguP2822 组合数问题(组合数,二维前缀和)

    P2822 组合数问题 输入输出样例 输入样例#1: 复制 1 2 3 3 输出样例#1: 复制 1 输入样例#2: 复制 2 5 4 5 6 7 输出样例#2: 复制 0 7 说明 [样例1说明] ...

  3. 51NOD 1134 最长上升子序列

    给出长度为N的数组,找出这个数组的最长递增子序列.(递增子序列是指,子序列的元素是递增的) 例如:5 1 6 8 2 4 5 10,最长递增子序列是1 2 4 5 10.   输入 第1行:1个数N, ...

  4. Ubuntu 设置文件默认打开的应用

    右键单击该文件,然后点击属性,打开属性面板 然后进入open with的选项,选择应用后,点击 set as default

  5. Cake slicing UVA - 1629

    UVA - 1629 ans[t][b][l][r]表示t到b行,l到r列那一块蛋糕切好的最小值d[t][b][l][r]表示t到b行,l到r列区域的樱桃数,需要预处理 #include<cst ...

  6. 并查集 HDOJ 1232 畅通工程

    题目传送门 /* 并查集(Union-Find)裸题 并查集三个函数:初始化Init,寻找根节点Find,连通Union 考察:连通边数问题 */ #include <cstdio> #i ...

  7. h5-27-存储/读取JS对象

    存储JS对象 <script type="text/javascript"> /*封装人员信息*/ function Person(id,name,age) { thi ...

  8. iphone 开发Categories 、Extensions 区别 --转

    Category和Extension这两个概念,即便对于Java程序员,可能也会感到陌生.这是Objective C为程序员提供的两个强大的动态机制——简单地说,它们允许程序员为已有的对象添加新的方法 ...

  9. 475 Heaters 加热器

    详见:https://leetcode.com/problems/heaters/description/ C++: class Solution { public: int findRadius(v ...

  10. 在 Windows 7 中禁用IPv6协议/IPv6隧道

    How to disable certain Internet Protocol version 6 (IPv6) components in Windows Vista, Windows 7 and ...