• 计蒜客31452 Supreme Number(找规律)


    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

    题意:求出最大的不超过n的由素数组成(所有数字组合情况都是素数)的元素
    分析:
        1、数字一定由1,2,3,5,7组成
        2、数字中2,5,7两两之间不能同时出现(25,52,27,72,57,75都不是素数),由此可以推断出全部符合的数都  不超过四位
        2、除1以外都不能重复出现两次和以上(会被11整除)例:313中33被11整除

    #include<iostream>
    #include<algorithm>
    #include<string.h>
    using namespace std;
    int main()
    {
    	int T,cnt=1;
    	scanf("%d",&T);
    	int a[20]={1,2,3,5,7,11,13,17,23,31,37,53,71,73,113,131,137,173,311,317};
    	while(T--)
    	{
    		int n=0;
    		char s[111];
    		scanf("%s",s);
    		printf("Case #%d: ",cnt++);
    		if(strlen(s)>=4)
    			printf("317
    ");
    		else
    		{
    			for(int i=0;s[i];i++)
    				n=n*10+s[i]-'0';
    			for(int i=19;i>=0;i--)
    				if(a[i]<=n){
    					printf("%d
    ",a[i]);
    					break;
    				}
    		}
    	}
    	return 0;
    }
    
  • 相关阅读:
    前端大牛们都学过哪些东西?
    自适应网页设计
    CSS border实现三角形
    wampServer 设置
    javascript 基础
    Oracle 优化相关
    Java(数据类型)基础面试
    Java 反射机制
    【设计模式】——代理模式
    【设计模式】——单例模式
  • 原文地址:https://www.cnblogs.com/aeipyuan/p/9893111.html
Copyright © 2020-2023  润新知