计蒜客 31452 - Supreme Number - [简单数学][2018ICPC沈阳网络预赛K题]
题目链接: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题]的更多相关文章
- 计蒜客 31453 - Hard to prepare - [递归][2018ICPC徐州网络预赛A题]
题目链接:https://nanti.jisuanke.com/t/31453 After Incident, a feast is usually held in Hakurei Shrine. T ...
- 计蒜客31452 Supreme Number(找规律)
A prime number (or a prime) is a natural number greater than 11 that cannot be formed by multiplying ...
- 计蒜客 31447 - Fantastic Graph - [有源汇上下界可行流][2018ICPC沈阳网络预赛F题]
题目链接:https://nanti.jisuanke.com/t/31447 "Oh, There is a bipartite graph.""Make it Fan ...
- 计蒜客 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 ...
- 计蒜客 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 ...
- [计蒜客] tsy's number 解题报告 (莫比乌斯反演+数论分块)
interlinkage: https://nanti.jisuanke.com/t/38226 description: solution: 显然$\frac{\phi(j^2)}{\phi(j)} ...
- 计蒜客 30996 - Lpl and Energy-saving Lamps - [线段树][2018ICPC南京网络预赛G题]
题目链接:https://nanti.jisuanke.com/t/30996 During tea-drinking, princess, amongst other things, asked w ...
- 计蒜客 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 ...
- 计蒜客 31459 - Trace - [线段树][2018ICPC徐州网络预赛G题]
题目链接:https://nanti.jisuanke.com/t/31459 样例输入 3 1 4 4 1 3 3 样例输出 10 题意: 二维平面上给出 $n$ 个点,每个点坐标 $\left( ...
随机推荐
- 创建Maven创建src/main/java提示反复
建立好一个Maven项目后.假设Java Resources资源文件下没有src/main/java目录,而且在手动创建这个文件时提示"已存在文件". 这说明,在这个项目配置中已经 ...
- Java实现策略模式的简单应用
在使用图像处理软件处理图片后,需要选择一种格式进行保存.然而各种格式在底层实现的算法并不相同,这刚好适合策略模式.编写程序,演示如何使用策略模式与简单工厂模式组合进行开发. 思路如下: 使用inter ...
- Nginx配置中文域名
今天碰到一个好玩的问题,还以为是nginx的缓存,各种清理就差把nginx卸载了,后来想想不对应该是中文域名的问题,对中文进行编码,搞定,如下: ... server { listen 80; ser ...
- eclipse下编译cocos2dx 3.0
先给自己科普一下, android sdk 是给java开发者用的, 咱C++开发者用的是android ndk, 所以就是使用ndk来编译cocos2dx程序了 使用命令行创建一个项目, 我这里创 ...
- 使用 urllib 处理 HTTP 异常
(1) 我们发起 HTTP 请求,有时会发生异常,如请求超时,登录密码错误,请求链接不存在等等,使用 urllib.request.URLError 可以捕获这些与 URL 相关的异常(2) urll ...
- MVC的路由设置【转】
转,MVC的路由设置. 后端获取路由里面action的参数,函数需要设置相同的参数名称才行. routes.MapRoute( "Default", "{controll ...
- Android学习之SeekBar(控制wav音频的声音)
使用SeekBar调节声音 SeekBar控件其实就是一个高级点的进度条,就像我们在听歌,看电影用的播放器上的进度条一样,是可以拖动的,可以改变进度的一个进度条控件! SeekBar常用属性: and ...
- C# 压缩 SharpZipLib
zip压缩与解压缩: 官方网站:http://icsharpcode.github.io/SharpZipLib/ 官网下载的资源并不是能够直接运行的,感觉是这个dll的编译,开源的 参考文档:htt ...
- Clock skewdetected. Your build may be incomplete.
解决方法: find . -type f | xargs -n touch make clean make
- 【图算法】Dijkstra算法及变形
图示: 模版: /* Dijkstra计算单源最短路径,并记录路径 m个点,n条边,每条边上的权值非负,求起点st到终点et的最短路径 input: n m st et 6 10 1 6 1 2 6 ...