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

题目来源

ACM-ICPC 2018 沈阳赛区网络预赛

题意

定义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的更多相关文章

  1. ACM-ICPC 2018 沈阳赛区网络预赛 K Supreme Number(规律)

    https://nanti.jisuanke.com/t/31452 题意 给出一个n (2 ≤ N ≤ 10100 ),找到最接近且小于n的一个数,这个数需要满足每位上的数字构成的集合的每个非空子集 ...

  2. 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 ...

  3. ACM-ICPC 2018 沈阳赛区网络预赛 K题

    题目链接: https://nanti.jisuanke.com/t/31452 AC代码(看到不好推的定理就先打表!!!!): #include<bits/stdc++.h> using ...

  4. 【ACM-ICPC 2018 沈阳赛区网络预赛 K】Supreme Number

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 显然每个数字只可能是1,3,5,7 然后如果3,5,7这些数字出现两次以上.显然两个3||5||7都能被11整除. 然后1的话最多能 ...

  5. 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. ...

  6. 图上两点之间的第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 ...

  7. ACM-ICPC 2018 沈阳赛区网络预赛 F. Fantastic Graph

    "Oh, There is a bipartite graph.""Make it Fantastic." X wants to check whether a ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. 快捷键设置 keyiing.json

    // 快捷键设置 keyiing.json // 将键绑定放入此文件中以覆盖默认值 [     /* // 转换大写     {         "key" : "ctr ...

  2. bzoj1238

    题解: 傻逼模拟题 果断的复制了题解(还没有c++题解?) 代码: program p2509; type arr=array[..] of boolean; var tot:longint; s:a ...

  3. SpringBoot document notes

    图片拷贝不过来,直接从github上下载 . 链接: https://github.com/DFX339/SpringBootDocumentNotes.git Create a example po ...

  4. 使用RxSwift 实现登录页面的条件绑定

    我们在使用MVC建构进行开发时,对登录页面用户名密码等进行的处理一般是这样的,点击登录按钮判断用户框以及密码框输入的合法性,用一堆if真是屎一般!或者用textfield的代理来进行响应其实也是屎一般 ...

  5. centos7安装配置zabbix4.0

    zabbix01    198.8.8.211    zabbix-server4.0 zabbix02    198.8.8.212    zabbix-agent4.0 一:zabbix服务端环境 ...

  6. VCL界面控件DevExpress VCL Controls发布v18.2.4|附下载

    DevExpress VCL Controls是 Devexpress公司旗下最老牌的用户界面套包.所包含的控件有:数据录入,图表,数据分析,导航,布局,网格,日程管理,样式,打印和工作流等,让您快速 ...

  7. Android开发 ---Button的OnClickListener的三种实现方法

    button的OnClickListener的三种实现方法 onclick事件的定义方法,分为三种,分别为 1.在xml中进行指定方法: 2.在Actitivy中new出一个OnClickListen ...

  8. Sample Credential Providers

        Windows Vista Sample Credential Providers Overview Contents Terms of Use Release Notes SampleCre ...

  9. dos命令:网络相关命令

    网络相关命令 一.Arp命令 1.介绍 ​ 显示和修改地址解析协议(ARP)使用的“IP 到物理”地址转换表. 2.语法 ARP -s inet_addr eth_addr [if_addr] ARP ...

  10. Arduino+Avr libc制作Badusb原理及示例讲解

    一. 前言 2014年美国黑帽大会上研究人员JakobLell和Karsten Nohl展示了badusb的攻击方法后,国内与badusb相关的文章虽然有了一些,但是大部分人把相关文章都阅读后还是会有 ...