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, 17 is a supreme number because 11, 77, 17 are all prime numbers or 11, and 1919 is not, because 99 is not a prime number.
Now you are given an integer (2≤N≤10^100), could you find the maximal supreme number that does not exceed N?
Input
In the first line, there is an integer (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 xx is the order number of the test case and yy is the answer.
样例输入复制
2 6 100
样例输出复制
Case #1: 5 Case #2: 73
题目来源
题意:求出不大于n的一个supreme Number. Supreme Number 是有素数组成的数且它的任意不连续的子串也是素数。
解析:其实这样的Supreme Number只是有几个,我们只需要手动写就知道了
#include<bits/stdc++.h>
using namespace std;
#define e exp(1)
#define pi acos(-1)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define ll long long
#define ull unsigned long long
#define mem(a,b) memset(a,b,sizeof(a))
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int main()
{
char s[1005];
int a[30]={1,2,3,5,7,11,13,17,23,31,37,53,71,73,113,131,137,173,311,313,317};
int T;scanf("%d",&T);
int cas=1;
while(T--)
{
scanf("%s",s);
if(strlen(s)>=4)printf("Case #%d: 317\n",cas++);
else
{
int sum=0;
for(int i=0; i<strlen(s); i++)
{
sum=sum*10+s[i]-'0';
}
int i;
for(i=0; i<22; i++)
{
if(sum<a[i])break;
}
i--;
printf("Case #%d: %d\n",cas++,a[i]);
}
}
return 0;
}