计蒜客 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( ...
随机推荐
- IOS UILineBreakMode的各种情况分析
typedef enum { UILineBreakModeWordWrap = 0, UILineBreakModeCharacterWrap, UILineBreakModeCl ...
- Windows程序执行过程
Windows应用程序: WinMain函数(入口函数): 1. 设计窗体类,注冊窗体类.WNDCLASS 2. 创建窗体,显示及更新窗体. 3. 消息循环. 窗体过程函数(回调函数):WindowP ...
- Window系统、主函数和窗体函数这三者之间的关系
理解Window系统.主窗体.窗体函数这三者之间的关系,对于编写Windows程序十分重要. 主函数和窗体函数都是由Windows系统来调用的函数.仅仅只是主函数是程序启动之后.系统首先调用的函数: ...
- VSCode------搭建.net core 2.0,并配置到IIS服务器
前奏 安装VSCode最新版: https://code.visualstudio.com/ 安装window server hosting,发布和部署到IIS使用: https://www.micr ...
- Linux+Redis实战教程_day01_Linux介绍与安装
1.Linux介绍(了解) 1.1.Linux和Windows的区别 Linux是一款操作系统.正规开发 服务器项目部署都是放在Linux操作系统上. Windows一款操作系统,民用操作系统.娱乐. ...
- fork(), waitpid()
NAME fork - create a child process SYNOPSIS #include <unistd.h> pid_t fork(void); RETURN VALUE ...
- BootStrap Table显示行号,并且分页后依然递增
bootStrap table 此处使用的是V1.9.0.在网上百度的方法是: { title: '序号', field: '', formatter: function (value, row, i ...
- Win10 取消桌面快捷键图标
新建文本文档 --- 写入如下内容 --- 改名为 .bat 并运行 @echo off color 2 reg delete HKCR\lnkfile /v IsShortcut /f reg de ...
- LNMP 简介
LNMP 代表的就是:Linux 操作系统下,Nginx + MySQL + PHP 这种网站服务器架构 工作流程:Nginx 直接处理静态请求,动态请求会转发给 php-fpm ( php 是作为一 ...
- 解决Sublime Text 3中文显示乱码问题(转)
解决Sublime Text 3中文显示乱码问题(转) 1.打开Sublime Text 3,按Ctrl+-打开控制行,复制粘贴以下python代码,然后回车运行. 2. 复制并粘贴如下代码: 2.重 ...