ACM-ICPC 2018 沈阳赛区网络预赛-K:Supreme Number
Supreme Number
A prime number (or a prime) is a natural number greater than 11 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 11.
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 (2≤N≤10100), could you find the maximal supreme number that does not exceed N?
Input
In the first line, there is an integer T (T≤100000) indicating the numbers of test cases.
In the following TT lines, there is an integer N (2≤N≤10^100).
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.
样例输入
2
6
100
样例输出
Case #1: 5
Case #2: 73
题目来源
题意
定义supreme number:一个数是素数,这个数的每一项都是1或素数,并且由这个数的每一位数组成的序列中,取出组成的任意子序列组成一个数,都是素数
求小于等于N的最大的supreme number
思路
打表找规律吧。。。最后会发现只有20个数符合supreme number的定义,然后把这20的数存入数组,输入整数N,在数组中查找符合要求的数就可以了
AC代码
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <limits.h>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <string>
#define ll long long
#define ull unsigned long long
#define ms(a) memset(a,0,sizeof(a))
#define pi acos(-1.0)
#define INF 0x7f7f7f7f
#define lson o<<1
#define rson o<<1|1
const double E=exp(1);
const int maxn=1e6+10;
const int mod=1e9+7;
using namespace std;
int vis[30]={1,2,3,5,7,11,13,17,23,31,37,53,71,73,113,131,137,173,311,317};
char num[maxn];
int main(int argc, char const *argv[])
{
ios::sync_with_stdio(false);
int t;
cin>>t;
int _=0;
while(t--)
{
int ans=0;
cin>>num;
int l=strlen(num);
cout<<"Case #"<<++_<<": ";
if(l>3)
cout<<317<<endl;
else
{
ans=0;
int res=10;
for(int i=0;i<l;i++)
ans=ans*res+num[i]-'0';
if(ans>=317)
cout<<317<<endl;
else
{
for(int i=0;i<21;i++)
if(vis[i]<=ans&&vis[i+1]>ans)
cout<<vis[i]<<endl;
}
}
}
return 0;
}
ACM-ICPC 2018 沈阳赛区网络预赛-K:Supreme Number的更多相关文章
- ACM-ICPC 2018 沈阳赛区网络预赛 K Supreme Number(规律)
https://nanti.jisuanke.com/t/31452 题意 给出一个n (2 ≤ N ≤ 10100 ),找到最接近且小于n的一个数,这个数需要满足每位上的数字构成的集合的每个非空子集 ...
- ACM-ICPC 2018 沈阳赛区网络预赛 K. Supreme Number
A prime number (or a prime) is a natural number greater than 11 that cannot be formed by multiplying ...
- ACM-ICPC 2018 沈阳赛区网络预赛 K题
题目链接: https://nanti.jisuanke.com/t/31452 AC代码(看到不好推的定理就先打表!!!!): #include<bits/stdc++.h> using ...
- 【ACM-ICPC 2018 沈阳赛区网络预赛 K】Supreme Number
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 显然每个数字只可能是1,3,5,7 然后如果3,5,7这些数字出现两次以上.显然两个3||5||7都能被11整除. 然后1的话最多能 ...
- ACM-ICPC 2018 沈阳赛区网络预赛-D:Made In Heaven(K短路+A*模板)
Made In Heaven One day in the jail, F·F invites Jolyne Kujo (JOJO in brief) to play tennis with her. ...
- 图上两点之间的第k最短路径的长度 ACM-ICPC 2018 沈阳赛区网络预赛 D. Made In Heaven
131072K One day in the jail, F·F invites Jolyne Kujo (JOJO in brief) to play tennis with her. Howe ...
- ACM-ICPC 2018 沈阳赛区网络预赛 F. Fantastic Graph
"Oh, There is a bipartite graph.""Make it Fantastic." X wants to check whether a ...
- ACM-ICPC 2018 沈阳赛区网络预赛 J树分块
J. Ka Chang Given a rooted tree ( the root is node 11 ) of NN nodes. Initially, each node has zero p ...
- ACM-ICPC 2018 焦作赛区网络预赛 K题 Transport Ship
There are NN different kinds of transport ships on the port. The i^{th}ith kind of ship can carry th ...
随机推荐
- 把旧系统迁移到.Net Core 2.0 日记 (13) --图形验证码
参考这篇文章: http://www.cnblogs.com/yuangang/p/6000460.html using System; using System.IO; using System.D ...
- Oracle中如何查询一个表的所有字段名和数据类型
Oracle中如何查询一个表的所有字段名和数据类型 查询语法 select A.COLUMN_NAME,A.DATA_TYPE from user_tab_columns A where TABLE_ ...
- laravel处理菜单保持的方法:
<!-- 左侧菜单区域 --> <div class="col-md-3"> @section('leftmenu') <div class=&quo ...
- 分布式链路追踪(Sleuth、Zipkin)
技术背景 在微服务架构中,随着业务发展,系统拆分导致系统调用链路愈发复杂,一个看似简单的前端请求可能最终需要调用很多次后端服务才能完成,那么当整个请求出现问题时,我们很难得知到底是哪个服务出了问题导致 ...
- global 全局变量 nonlocal 局部变量
# x= # def func(): # x= # # func() # print(x) # x=[] # def func(): # x.append() # x.append() # x.app ...
- bluemix部署(二)构建kubernetes工作环境
本文接上篇.在bluemix中构建kubernetes容器. 1.创建集群 左上角的三横,选容器,然后创建集群. 注意区域,免费版,给个名字,创建集群吧. 继续正在部署,这个可能要15-30分钟,真不 ...
- 自己写了一个解析json为table的工具类
还需要完善的包括,css的封装,触发事件,数据的获得处理: <!DOCTYPE html> <html> <head> <meta charset=" ...
- 《Python》进程之间的通信(IPC)、进程之间的数据共享、进程池
一.进程间通信---队列和管道(multiprocess.Queue.multiprocess.Pipe) 进程间通信:IPC(inter-Process Communication) 1.队列 概念 ...
- error MSB8008: 指定的平台工具集(V120)未安装或无效。
打开项目属性->配置属性->右面,平台工作集,选为v10 如下图
- js 将文本转换为数据 string number
<span class="Span" > <p>123.81</p> <a> dejiw</a> </span&g ...