计蒜客 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( ...
随机推荐
- SpringBoot------Eclipce配置Spring Boot
步骤一: 步骤二: 点击左下角Eclipse图标下的“Popular”菜单,选择Spring安装(已安装的插件在Installed中显示),一直按步骤确定就好了,如果中途下载超时什么的,就看看自己的网 ...
- SPREAD for Windows Forms 代码片段
'スクロールバーの移動 FpSpread1.ShowColumn(, , HorizontalPosition.Left) 'SetActiveCellの後.LeaveCellを呼び出す Dim ss ...
- 5 -- Hibernate的基本用法 --2 1 Hibernate 下载和安装
1. 下载Hibernate压缩包 2. 解压:文件结构 ⊙ documentation : 该路径下存放了Hibernate的相关文档,包括Hibernate的参考文档和API文档等. ⊙ lib ...
- 【GIS】GDAL Python 影像裁剪
# -*- coding: utf-8 -*- """ Created on Fri Nov 30 11:45:03 2018 @author: Administrato ...
- centos7 更改主机名
在CentOS或RHEL中,有三种定义的主机名:a.静态的(static),b.瞬态的(transient),以及 c.灵活的(pretty).“静态”主机名也称为内核主机名,是系统在启动时从/etc ...
- Python 编程技巧
Python 生成器 Python 处理文件 Python 异常处理 Python 处理输入输出 Python 处理命令行参数 Python 对文件做校验 Python 对目录做遍历 Python 调 ...
- mybatis 之 parameterType="java.util.HashMap">
/** * 根据goods_no 和 goods_id 来查询商品信息 * * @param goodsNos * @return */ public List<Goods> getGoo ...
- 说说C与汇编之间的互相联系(转)
在嵌入式系统开发中,目前使用的主要编程语言是C和汇编,C++已经有相应的编译器,但是现在使用还是比较少的.在稍大规模的嵌入式软件中,例如含有OS,大部分的代码都是用C编写的,主要是因为C语言的结构比较 ...
- iOS - 实现语言本地化/国际化
实现iOS语言本地化/国际化(图文详解) 前言 语言本地化,又叫做语言国际化.是指根据用户操作系统的语言设置,自动将应用程序的语言设置为和用户操作系统语言一致的语言.往往一些应用程序需要提供给多个 ...
- var_dump出现省略号的问题
xdebug.var_display_max_children=128xdebug.var_display_max_data=512xdebug.var_display_max_depth=5