• 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. Unable to resolve target 'android-20'

    使用eclipse编写android的app时,出现错误:Unable to resolve target 'android-20'. 参看链接: http://blog.csdn.net/u0134 ...

  2. IoC是一个很大的概念,可以用不同的方式实现。

    IoC是一个很大的概念,可以用不同的方式实现.其主要形式有两种: ◇ 依赖查找:容器提供回调接口和上下文条件给组件.EJB和Apache Avalon 都使用这种方式.这样一来,组件就必须使用容器提供 ...

  3. e681. 基本的打印程序

    Note that (0, 0) of the Graphics object is at the top-left of the actual page, outside the printable ...

  4. Unity中的Transform Gizmo中的Pivot和Center

    选择中心(Center)意味着使用当前所选所有物体的共同轴心, 选择轴心(Pivot)意味着将使用各个物体的实际轴心 区别在于是否选中了多个物体或者有层级关系的物体. 第一张图是Center,中心在组 ...

  5. DOM编程 学习笔记(二)

    学习内容: 1.document对象 2.event对象 该对象将标记型文档进行封装 该对象的作用,是对可标记型文档进行操作 常见操作,想要实现动态效果,需要对节点操作,那么先获取到这个节点,想获取节 ...

  6. 【甘道夫】通过Mahout构建贝叶斯文本分类器案例具体解释

    背景&目标: 1.sport.tar 是体育类的文章,一共同拥有10个类别.    用这些原始材料构造一个体育类的文本分类器,并測试对照bayes和cbayes的效果:    记录分类器的构造 ...

  7. CentOS查看登录用户以及踢出用户

    查看登录用户,使用w命令 [root@lnmp ~]# w 18:51:18 up 35 min,  2 users,  load average: 0.00, 0.00, 0.00 USER     ...

  8. SharePoint 2013 一次性上传文件大小限制

    默认是250MB,最大一次上传文件不超过2G The defaut size is 250MB and maximun upload size is 2047MB. It's can't greate ...

  9. mysql数据库中,通过mysqldump工具仅将某个库的所有表的定义进行转储

    需求描述: 在研究mysqldump工具的使用,想的是如何将某个库下的,或者某个表的表的定义(表结构创建语句)进行转储 操作过程: 1.通过--no-data参数,就可以将某个库的表定义进行转储 [m ...

  10. 使用HTML5 的跨域通信机制进行数据同步

    离线应用系统的设计目标就是在网络离线情况下依然可以操作我们的应用系统,并在网络畅通的情况下与服务器进行数据交互. 所以离线应用系统最终会做成类似C/S架构的客户端应用程序.这边基于Chrome或者 S ...