计蒜客 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( ...
随机推荐
- [OpenCV] IplImage and Operation
IplImage 一.资源 In this chapter, APIs will make U crazy. Good luck! Next, Review Linear Algebra. Ref: ...
- vuejs使用FormData对象,ajax上传图片文件
我相信很多使用vuejs的朋友,都有采用ajax上传图片的需求,因为前后端分离后,我们希望都能用ajax来解决数据问题,传统的表单提交会导致提交成功后页面跳转,而使用ajax能够无刷新上传图片等文件. ...
- CentOS7上Redis安装与配置
一.redis安装(注意:最好先安装一遍gcc->yum -y install gcc:如果系统本身缺少,make时候会出错,后期修改稍麻烦) 1.wget命令下载 wget http://do ...
- Linux关闭Tomcat为什么要用Kill,而不是shutdown.sh
Linux关闭Tomcat为什么要用Kill,而不是shutdown.sh >>>>>>>>>>>>>>>&g ...
- dedeCMS解码
var str = 'arrs1[]=99&arrs1[]=102&arrs1[]=103&arrs1[]=95&arrs1[]=100&arrs1[]=98& ...
- 【RF库测试】算法运算
- XML转JSON工具类
原文地址:http://blog.csdn.net/lovesummerforever/article/details/26396465 1.pom依赖 <dependency> < ...
- (转载)JVM实现synchronized的底层机制
目前在Java中存在两种锁机制:synchronized和Lock,Lock接口及其实现类是JDK5增加的内容,其作者是大名鼎鼎的并发专家Doug Lea.本文并不比较synchronized与Loc ...
- Material Design系列第五篇——Working with Drawables
Working with Drawables This lesson teaches you to Tint Drawable Resources Extract Prominent Colors f ...
- 深入理解 Neutron -- OpenStack 网络实现(3):VXLAN 模式
问题导读1.VXLAN 模式下,网络的架构跟 GRE 模式类似,他们的不同点在什么地方?2.网络节点的作用是什么?3.tap-xxx.qr-xxx是指什么? 接上篇:深入理解 Neutron -- O ...