• 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. Nodejs入门手记 (01):Hello World的WEB程序

    声明:本文为原创文章,如需转载,请注明来源并保留原文链接Allong,谢谢! “滚滚长江东逝水,浪花淘尽英雄.是非成败转头空.” - <临江仙·杨慎·明> 很熟悉的旋律,鸡汤了一下:高考是 ...

  2. 如何研究某个gene的ceRNA 网络

    研究人员针对 PTEN 这个关键的抑癌基因,来探究调控该基因表达的ceRNA 网络: 分析策略: 1)预测能调控该基因的miRNAs 通过miRanda 软件预测和实验验证相结合的方式,挑选出 miR ...

  3. Qt 定时器Timer使用

    From: http://dragoon666.blog.163.com/blog/static/107009194201092602326598/ 1.新建Gui工程,在主界面上添加一个标签labe ...

  4. [转]Git学习笔记与IntelliJ IDEA整合

    Git学习笔记与IntelliJ IDEA整合 一.Git学习笔记(基于Github) 1.安装和配置Git 下载地址:http://git-scm.com/downloads Git简要使用说明:h ...

  5. jQuery-处理class属性

    1.addClass方法 为每个匹配的元素添加指定的样式类名 参数类型说明: 1)class名称(字符串) 每个匹配元素添加的一个或多个用空格隔开的样式名 2)function(index, curr ...

  6. Oracle:create pfile from spfile:rac下要小心该操作啊!

    默认在原位置创建一个pfile的ora初始化参数文件!! 这在rac下会带来问题,因为rac下,当使用asm存储时,instance的启动参数文件就是pfile(其内容是指向一个spfile).如果不 ...

  7. 简易2D横版RPG游戏制作

    Unity学习笔记1 简易2D横版RPG游戏制作 http://m.blog.csdn.net/article/details?id=24601905

  8. 无法查找或打开 PDB 文件

    emmmmmmmmmmmmm...建议:不用管!!! 参考: 在 Visual Studio 调试器中指定符号 (.pdb) 和源文件 https://msdn.microsoft.com/zh-cn ...

  9. CString TCHAR互相转换

    CString->TCHAR*的转化可以用函数GetBuffer() // 原型:LPTSTR GetBuffer( int nMinBufLength ); CString str(_T(&q ...

  10. mysql数据库,如何进行数据目录的初始化操作

    需求描述: 当将mysql的二进制包解压之后,只有通过初始化数据库的数据目录,创建系统表之后才能使用mysql Server 数据库版本:5.5.57-log 操作过程: 1.通过解压之后的mysql ...