题目链接:https://nanti.jisuanke.com/t/31452

A prime number (or a prime) is a natural number greater than $1$ 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 $1$.

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 N (2≤N≤1e100), could you find the maximal supreme number that does not exceed $N$?

Input
In the first line, there is an integer (T≤100000) indicating the numbers of test cases.

In the following T lines, there is an integer N (2≤N≤10100).

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.

注意:

子序列(Subsequence)子串(Substring)是不一样的,子序列可以是不连续的。

题意:

若一个数的所有非空子序列是素数(或者 $1$),则称它为“supreme number”,

现在给出一个 $N$,要求不大于 $N$ 的最大的supreme number。

题解:

考虑五位数:首先由于2,5,7只要有两个同时出现,就不行,所以2,5,7只能挑一个;又3不能出现超过1次,所以只能要一个3;那么剩下3个空位只能填1,但一旦有111就不是素数,就不行。

所以超过四位的数统统不行,则只要暴力把四位以内的数全部找出来即可。

AC代码:

#include<bits/stdc++.h>
using namespace std;
int n[]={,,,,,,,,,,,,,,,,,,,,};
char str[];
int main()
{
int T;
cin>>T;
for(int kase=;kase<=T;kase++)
{
scanf("%s",str);
int len=strlen(str);
if(len>=) printf("Case #%d: %d\n",kase,n[]);
else
{
int num=,k=;
for(int i=len-;i>=;i--)
{
num+=(str[i]-'')*k;
k*=;
}
printf("Case #%d: %d\n",kase,n[upper_bound(n+,n+,num)-n-]);
}
}
}

计蒜客 31452 - Supreme Number - [简单数学][2018ICPC沈阳网络预赛K题]的更多相关文章

  1. 计蒜客 31453 - Hard to prepare - [递归][2018ICPC徐州网络预赛A题]

    题目链接:https://nanti.jisuanke.com/t/31453 After Incident, a feast is usually held in Hakurei Shrine. T ...

  2. 计蒜客31452 Supreme Number(找规律)

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

  3. 计蒜客 31447 - Fantastic Graph - [有源汇上下界可行流][2018ICPC沈阳网络预赛F题]

    题目链接:https://nanti.jisuanke.com/t/31447 "Oh, There is a bipartite graph.""Make it Fan ...

  4. 计蒜客 30990 - An Olympian Math Problem - [简单数学题][2018ICPC南京网络预赛A题]

    题目链接:https://nanti.jisuanke.com/t/30990 Alice, a student of grade 6, is thinking about an Olympian M ...

  5. 计蒜客 31451 - Ka Chang - [DFS序+树状数组][2018ICPC沈阳网络预赛J题]

    题目链接:https://nanti.jisuanke.com/t/31451 Given a rooted tree ( the root is node $1$ ) of $N$ nodes. I ...

  6. [计蒜客] tsy's number 解题报告 (莫比乌斯反演+数论分块)

    interlinkage: https://nanti.jisuanke.com/t/38226 description: solution: 显然$\frac{\phi(j^2)}{\phi(j)} ...

  7. 计蒜客 30996 - Lpl and Energy-saving Lamps - [线段树][2018ICPC南京网络预赛G题]

    题目链接:https://nanti.jisuanke.com/t/30996 During tea-drinking, princess, amongst other things, asked w ...

  8. 计蒜客 31460 - Ryuji doesn't want to study - [线段树][2018ICPC徐州网络预赛H题]

    题目链接:https://nanti.jisuanke.com/t/31460 Ryuji is not a good student, and he doesn't want to study. B ...

  9. 计蒜客 31459 - Trace - [线段树][2018ICPC徐州网络预赛G题]

    题目链接:https://nanti.jisuanke.com/t/31459 样例输入 3 1 4 4 1 3 3 样例输出 10 题意: 二维平面上给出 $n$ 个点,每个点坐标 $\left( ...

随机推荐

  1. webApi之FromUri和FromBody区别

    public Link GetLink([FromUri] FileRequest fileRequest) { if (ModelState.IsValid) { var xml = WebConf ...

  2. 在netbeans下使用调试PHP的插件XdeBug

    本人的开发环境: wamp最新官网wampserver2.2d-x32版. 下载点:http://nchc.dl.sourceforge.net/project/wampserver/WampServ ...

  3. nodejs服务器部署教程四

    nodejs服务器部署最后一篇文章,部署ssl证书,升级http为https,其实网上相关教程有很多,但是略麻烦,本教程让你一切从简,5分钟搞定https,免费一年哦 申请ssl证书 免费申请的机构有 ...

  4. cocos2d-x 3.0 在lua中调用自定义类

    环境 windows8, cocos2d-x 3.0, 现在开始安装需要的一些其它包 1. 按README.mdown文档上面要求的, 下载在windows下要安装的东东, 主要就是python2.7 ...

  5. mongodb常用操作命令(待续)

    1. 开启mongodb命令 >mongo 默认链接到test数据库 2. 显示所有数据库>show dbs 3.切换数据库>use 数据库名 4.查找数据库里某张表的所有成员> ...

  6. 【ArcGIS】ArcGIS Android SDK

    1.错误提示 11-06 18:12:17.553: A/libc(11929): Fatal signal 11 (SIGSEGV), code 1, fault addr 0x0 in tid 1 ...

  7. Spark-scala-API

    1.sc.version2.集群对象:SparkContext:获得Spark集群的SparkContext对象,是构造Spark应用的第一步!SparkContext对象代表 整个 Spark集群, ...

  8. PDF XSS

    漏洞测试: 下面,我们介绍如何把 JavaScript 嵌入到 PDF 文档之中.我使用的是迅捷 PDF 编辑器未注册版本 1.启动迅捷 PDF 编辑器打开一个 PDF 文件,或者使用“创建 PDF ...

  9. HTML 换行

    <br /> 标签可以用于换行 <!DOCTYPE HTML> <html> <body> <p> I like Playing. < ...

  10. osgearth cache

    <map name="readymap.org" type="geocentric"> <options> <!--Specify ...