zoukankan      html  css  js  c++  java
  • 沈阳网络赛K-Supreme Number【规律】

    •  26.89%
    •  1000ms
    •  131072K

    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

    题目来源

    ACM-ICPC 2018 沈阳赛区网络预赛

    题意:

    要找一个不大于n的数 这个数的子序列都是质数或1

    思路:

    注意, 子序列是先后顺序不变但是不一定连续。子串要求要连续。

    所以这些数是有限的,而且个数很少,可以手算的出来

    首先一位的只有1,2,3,5,7

    2和5只能在最高位

    除了1之外其他数只可能最多出现一次

    因此,只有20个数:1, 2, 3, 5, 7, 11, 13, 17, 23, 31,37, 53, 71, 73, 113, 131, 137, 173, 311, 317

    
    #include<iostream>
    #include<stdio.h>
    #include<string.h>
    #include<algorithm>
    #include<stack>
    #include<queue>
    #include<map>
    #include<vector>
    #include<cmath>
    #include<set>
    //#include<bits/stdc++.h>
    #define inf 0x7f7f7f7f7f7f7f7f
    using namespace std;
    typedef long long LL;
    
    int t;
    char s[105];
    int nums[100] = {1, 2, 3, 5, 7, 11, 13, 17, 23, 31,
     37, 53, 71, 73, 113, 131, 137, 173, 311, 317};
    
    
    int main()
    {
    	cin >> t;
    	for (int cas = 1; cas <= t; cas++) {
    		cin >> s;
    		if(strlen(s) >= 4){
                printf("Case #%d: 317
    ", cas);
                continue;
    		}
    		int n = 0;
    		for(int i = 0; i < strlen(s); i++){
                n *= 10;
                n += s[i] - '0';
    		}
    
    		int ans = 0;
            for(int i = 0; i < 20; i++){
                if(n >= nums[i]){
                    ans = nums[i];
                }
                else{
                    break;
                }
            }
    
            printf("Case #%d: %d
    ", cas, ans);
    	}
    	return 0;
    }
    
  • 相关阅读:
    java 实现串口通信
    下载 Microsoft .NET Framework 4和4.5.2(独立安装程序)
    vm15.5.1安装Mac os X
    开源网盘系统
    Photoshop另存为图片为.ico格式(图标文件)的插件
    VeraCrypt(文件加密工具)创建和加载“文件型加密卷”的步骤
    强制浏览器字体为宋体或其他指定的字体
    超微主板风扇模式
    通过URL获取该页面内的所有超链接
    photoshop新建时提示“无法完成请求,因为暂存盘已满”的解决方案
  • 原文地址:https://www.cnblogs.com/wyboooo/p/9643364.html
Copyright © 2011-2022 走看看