Supreme Number(找规律)

题目链接

                                                                            Supreme Number

A prime number (or a prime) is a natural number greater than 
1that 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 1.

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 N (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 T lines, there is an integer N (2 ≤ N ≤ 10100 ).

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 沈阳赛区网络预赛

思路:先说一下题目意思吧,求不超过N的最大supreme素数,该素数满足由其任意几位数字组成的一个新的数字均为素数。很显然,应该打一个表。全排列搞一搞就行了。

代码:

#include<iostream>
#include<cstdio>
#include<string>
#define in(x) scanf("%d",&x)
#define out(x) printf("%d",x)
using namespace std;
int k[100]={1,2,3,5,7,11,13,17,23,31,37,53,71,73,113,131,137,173,311,317};
int main()
{
	string str;
	int t;
	in(t);
	for(int j=1;j<=t;j++){
		cin>>str;
		printf("Case #%d: ",j);
		if(str.size()>=4) printf("317\n");
		else{
			int temp=0;
			for(int i=0;i<str.size();i++){
				temp=temp*10+str[i]-'0';
			}
			for(int i=19;i>=0;i--){
				if(temp>=k[i]){
					printf("%d\n",k[i]);
					break;
				}
			}
		}
	}
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值