• 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\n", 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\n", cas, ans);
}
return 0;
}

沈阳网络赛K-Supreme Number【规律】的更多相关文章

  1. ACM-ICPC 2018 沈阳赛区网络预赛 K Supreme Number(规律)

    https://nanti.jisuanke.com/t/31452 题意 给出一个n (2 ≤ N ≤ 10100 ),找到最接近且小于n的一个数,这个数需要满足每位上的数字构成的集合的每个非空子集 ...

  2. 2018 ICPC 沈阳网络赛预赛 Supreme Number(找规律)

    [传送门]https://nanti.jisuanke.com/t/31452 [题目大意]:给定一个数字(最大可达10100),现在要求不超过它的最大超级质数.超级质数定义:对于一个数,把它看成数字 ...

  3. ACM-ICPC 2018 沈阳赛区网络预赛 K. Supreme Number

    A prime number (or a prime) is a natural number greater than 11 that cannot be formed by multiplying ...

  4. 2018 ICPC 沈阳网络赛

    2018 ICPC 沈阳网络赛 Call of Accepted 题目描述:求一个算式的最大值与最小值. solution 按普通算式计算方法做,只不过要同时记住最大值和最小值而已. Convex H ...

  5. 2019-ACM-ICPC-沈阳区网络赛-K. Guanguan's Happy water-高斯消元+矩阵快速幂

    2019-ACM-ICPC-沈阳区网络赛-K. Guanguan's Happy water-高斯消元+矩阵快速幂 [Problem Description] 已知前\(2k\)个\(f(i)\),且 ...

  6. 计蒜客 31452 - Supreme Number - [简单数学][2018ICPC沈阳网络预赛K题]

    题目链接:https://nanti.jisuanke.com/t/31452 A prime number (or a prime) is a natural number greater than ...

  7. 沈阳网络赛 F - 上下界网络流

    "Oh, There is a bipartite graph.""Make it Fantastic." X wants to check whether a ...

  8. 沈阳网络赛D-Made In Heaven【k短路】【模板】

    One day in the jail, F·F invites Jolyne Kujo (JOJO in brief) to play tennis with her. However, Pucci ...

  9. 2016沈阳网络赛 odd-even number

    odd-even number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

随机推荐

  1. (转)sqlite3生成lib遇到的问题

    今天想用一用sqlite,但是下载后发现只有DLL,没有LIB,只能自己生成了.在H:/Program Files/Microsoft Visual Studio 8/VC/bin里面有个lib.ex ...

  2. 用IFrame作预览pdf,图片

    <iframe id="my_img" src="@ViewBag.path" width="100%" frameborder=&q ...

  3. rdesktop连接远程windows

    $ info rdesktop   //看一下帮助信息吧$rdesktop 192.168.1.1 //打开了一个8位色彩的,$rdesktop -a 16 192.168.1.1 //这个是16位色 ...

  4. MySQL<表单&集合查询>

    表单查询 简单查询 SELECT语句 查询所有字段 指定所有字段:select 字段名1,字段名2,...from 表名; select * from 表名; 查询指定字段 select 字段名1,字 ...

  5. POJ 1038 Bug Integrated Inc(状态压缩DP)

    Description Bugs Integrated, Inc. is a major manufacturer of advanced memory chips. They are launchi ...

  6. 上传绕过WAF的tips大全

    原始默认状态: ——WebKitFormBoundary2smpsxFB3D0KbA7D Content-Disposition: form-data; name=”filepath”; filena ...

  7. 【RF库Collections测试】Remove From Dictionary

    Name:Remove From DictionarySource:Collections <test library>Arguments:[ dictionary | *keys ]Re ...

  8. html的初识

    今天我们学习了Html语言,感觉学习这个是我期望很久的啦,之前在百度上面也看过html教程,但是看过之后也忘记啦,太多需要记忆的,所以也没记得什么啦.甚是遗憾啊,总感觉html需要学习好多东西啦的,但 ...

  9. PyQt4开关按钮ToggleButton

    PyQt4没有开关按钮部件.但是我们可以使用在特殊状态下的QPushButton部件来创建开关按钮.而所谓的开关按钮就是一个具有按下和未按下两种状态的普通赶牛.用户可以通过单击按钮来切换其开或者关的状 ...

  10. 《转》我眼中的C# 3.0

    本文转载自Allen Lee's Magic 缘起 每次有新技术发布时,我们总能感受到两种截然不同的情绪:一种是恐惧和抵抗,伴随着这种情绪的还有诸如"C# 2.0用的挺好的,为什么要在C# ...