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的速度的。

最新文章

  1. 【转】png优化相关
  2. solaris tar 命令exclude使用
  3. underscore.js库的浅析
  4. O(nlogn)LIS及LCS算法
  5. JSON 之 SuperObject(4): 增、删、改
  6. hdu 1092 A+B for Input-Output Practice (IV)
  7. Hadoop的数据压缩
  8. 使用Jsoup实现java爬虫(非原创)
  9. hihoCoder #1465 : 后缀自动机五&#183;重复旋律8
  10. 【比赛游记】FJOI2019瞎打记
  11. 电脑异常断电,IDEA崩溃
  12. java并发:读写锁ReadWriteLock
  13. poj3186(区间DP)
  14. 浅谈 JSONP
  15. C-C和指针作业题(第一章)
  16. SQL多行字符串按条件合并
  17. Yii2 init 与 beforeAction 区别
  18. php中die(),exit(),return的区别
  19. Python入门基础:代码的编码风格
  20. vue - for遍历数组

热门文章

  1. 洛谷 - P2152 - SuperGCD - 高精度
  2. FZU2277 Change(dfs序+树状数组)
  3. Codeforces Round #331 (Div. 2)【未完待续】
  4. js和jquery给iframe src赋值的3种方法
  5. Seek the Name, Seek the Fame POJ - 2752
  6. 谷歌编码风格内容,新建一个xml文件,复制进去就可以在eclipse里面用了,命名--eclipse-java-google-style.xml
  7. Linux上不了网——wget无法解析主机
  8. qconbeijing2015
  9. 模板方法模式及php实现
  10. CG Shader常用函数