zoukankan      html  css  js  c++  java
  • 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 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 11.

    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  (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 TT lines, there is an integer N (2≤N≤10^100).

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

    题意

    定义supreme number:一个数是素数,这个数的每一项都是1或素数,并且由这个数的每一位数组成的序列中,取出组成的任意子序列组成一个数,都是素数

    求小于等于N的最大的supreme number

    思路

    打表找规律吧。。。最后会发现只有20个数符合supreme number的定义,然后把这20的数存入数组,输入整数N,在数组中查找符合要求的数就可以了

    AC代码

    #include <stdio.h>
    #include <string.h>
    #include <iostream>
    #include <algorithm>
    #include <math.h>
    #include <limits.h>
    #include <map>
    #include <stack>
    #include <queue>
    #include <vector>
    #include <set>
    #include <string>
    #define ll long long
    #define ull unsigned long long
    #define ms(a) memset(a,0,sizeof(a))
    #define pi acos(-1.0)
    #define INF 0x7f7f7f7f
    #define lson o<<1
    #define rson o<<1|1
    const double E=exp(1);
    const int maxn=1e6+10;
    const int mod=1e9+7;
    using namespace std;
    int vis[30]={1,2,3,5,7,11,13,17,23,31,37,53,71,73,113,131,137,173,311,317};
    char num[maxn];
    int main(int argc, char const *argv[])
    {
    	ios::sync_with_stdio(false);
    	int t;
    	cin>>t;
    	int _=0;
    	while(t--)
    	{
    		int ans=0;
    		cin>>num;
    		int l=strlen(num);
    		cout<<"Case #"<<++_<<": ";
    		if(l>3)
    			cout<<317<<endl;
    		else
    		{
    			ans=0;
    			int res=10;
    			for(int i=0;i<l;i++)
    				ans=ans*res+num[i]-'0';
    			if(ans>=317)
    				cout<<317<<endl;
    			else
    			{
    				for(int i=0;i<21;i++)
    					if(vis[i]<=ans&&vis[i+1]>ans)
    						cout<<vis[i]<<endl;
    			}
    		}
    	}
    	return 0;
    }
  • 相关阅读:
    TeamWork#3,Week5,Scrum Meeting 11.16
    TeamWork#3,Week5,Scrum Meeting 11.6, 11.7, 11.11, 11.12
    TeamWork#3,Week5,Scrum Meeting 11.15
    TeamWork#3,Week5,Scrum Meeting 11.14
    TeamWork#3,Week5,Scrum Meeting 11.13
    TeamWork#3,Week5,Scrum Meeting 11.9
    TeamWork#3,Week5,Bing Input Method vs Sogou Input Method
    TeamWork#3,Week5,Scrum Meeting 11.4
    Daily Scrum10 11.14
    Daily Scrum9 11.13
  • 原文地址:https://www.cnblogs.com/Friends-A/p/10324360.html
Copyright © 2011-2022 走看看