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 NN as the supreme number if and only if each number made up of an non-empty subsequence of all the numeric digits of NN must be either a prime number or 11.

For example, 1717 is a supreme number because 11, 77, 1717 are all prime numbers or 11, and 1919 is not, because 99 is not a prime number.

Now you are given an integer N\ (2 \leq N \leq 10^{100})N (2≤N≤10100), could you find the maximal supreme number that does not exceed NN?

Input

In the first line, there is an integer T\ (T \leq 100000)T (T≤100000) indicating the numbers of test cases.

In the following TT lines, there is an integer N\ (2 \leq N \leq 10^{100})N (2≤N≤10100).

Output

For each test case print "Case #x: y", in which xxis the order number of the test case and yy is the answer.

样例输入复制

2
6
100

样例输出复制

Case #1: 5
Case #2: 73

题目来源

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

题意:一个supreme数是其的所有子集都是质数或者1(可以是不连续的子集),求小于n的最大的supreme数

分析:考虑单独的一个数是supreme数或1的有1,2,3,5,7,二位数是supreme数的有73,71,53,37,31,23,17,13,11,三位数是supreme数的有317,311,173,137,131,113,四位数没有supreme数

所以我们直接用个数组保存下来这些supreme数,然后看输入的数处于哪个范围就行

AC代码:

#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#define ls (r<<1)
#define rs (r<<1|1)
#define debug(a) cout << #a << " " << a << endl
using namespace std;
typedef long long ll;
const ll maxn = 1e5+10;
const ll mod = 1e9+7;
const double pi = acos(-1.0);
const double eps = 1e-8;
ll prime[] = {317,311,173,137,131,113,73,71,53,37,31,23,17,13,11,7,5,3,2,1};
int main() {
ll T;
cin >> T;
for( ll cas = 1; cas <= T; cas ++ ) {
string s;
cin >> s;
cout << "Case #" << cas << ": ";
if( s.length() >= 4 ) {
cout << 317 << endl;
} else {
ll sum = 0;
for( ll i = 0; i < s.length(); i ++ ) {
sum = sum*10 + (s[i]-'0');
}
for( ll i = 0; i < 20; i ++ ) {
if( sum >= prime[i] ) {
cout << prime[i] << endl;
break;
}
}
}
}
return 0;
}

  

Supreme Number 2018沈阳icpc网络赛 找规律的更多相关文章

  1. ACM-ICPC 2018 沈阳赛区(网络赛)

    D.Made In Heaven One day in the jail, F·F invites Jolyne Kujo (JOJO in brief) to play tennis with he ...

  2. Trace 2018徐州icpc网络赛 (二分)(树状数组)

    Trace There's a beach in the first quadrant. And from time to time, there are sea waves. A wave ( xx ...

  3. Ryuji doesn't want to study 2018徐州icpc网络赛 树状数组

    Ryuji is not a good student, and he doesn't want to study. But there are n books he should learn, ea ...

  4. Trace 2018徐州icpc网络赛 思维+二分

    There's a beach in the first quadrant. And from time to time, there are sea waves. A wave ( xx , yy) ...

  5. Features Track 2018徐州icpc网络赛 思维

    Morgana is learning computer vision, and he likes cats, too. One day he wants to find the cat moveme ...

  6. hdu 4731 2013成都赛区网络赛 找规律

    题意:找字串中最长回文串的最小值的串 m=2的时候暴力打表找规律,打表可以用二进制枚举

  7. 2019沈阳icpc网络赛H德州扑克

    题面:https://nanti.jisuanke.com/t/41408 题意:A,2,3,4,5,6,7,8,9,10,J,Q,K,13张牌,无花色之分,val为1~13. 给n个人名+n个牌,输 ...

  8. Aggregated Counting-----hdu5439(2015 长春网络赛 找规律)

    #include<stdio.h> #include<string.h> #include<iostream> #include<math.h> #in ...

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

随机推荐

  1. DDMS 视图 Emulator Control 为灰色

    Emulator Control 模拟发送短信时,发现所有选项均为灰色,如图所示: 解决方法: 确认以下四种情形或方法 已测试 Genymotion 模拟器和真机均不行,而Eclipse自带模拟器可以 ...

  2. Django是如何防止注入攻击-XSS攻击-CSRF攻击

    注入攻击-XSS攻击-CSRF攻击介绍请访问:https://www.cnblogs.com/hwnzy/p/11219475.html Django防止注入攻击 Django提供一个抽象的模型层来组 ...

  3. Spring Cloud 之 Stream.

    一.简介 Spring Cloud Stream 是一个用来为微服务应用构建消息驱动能力的框架. Spring Cloud Stream 为一些供应商的消息中间件产品(目前集成了 RabbitMQ 和 ...

  4. 基于http(s)协议的模板化爬虫设计

    声明:本文为原创,转载请注明出处 本文总共三章,前面两章废话吐槽比较多,想看结果的话,直接看第三章(后续会更新,最近忙着毕设呢,毕设也是我自己做的,关于射频卡的,有时间我也放上来,哈哈). 一,系统总 ...

  5. 使用Jasypt对SpringBoot配置文件加密

    # **前言** 在日前安全形势越来越严重的情况下,让我意识到在项目中存在一个我们经常忽略的漏洞,那就是我们的项目的配置文件中配置信息的安全,尤其是数据库连接的用户名和密码的安全.所以这里我们就需要对 ...

  6. Java基础的一些知识点(一):接口interface

    1.接口的含义 接口可以理解成统一的协议, 而接口中的属性也属于协议中的内容.但是接口的属性都是公共的,静态的,最终的. 接口的成员特点: 1.成员变量只能是常量,默认修饰符 public stati ...

  7. HTML/CSS:block,inline和inline-block概念和区别

    总体概念 block和inline这两个概念是简略的说法,完整确切的说应该是 block-level elements (块级元素) 和 inline elements (内联元素).block元素通 ...

  8. 基于RBAC的权限框架

    RBAC权限框架(Role-Based Access Control)基于角色的权限访问控制的框架,通过用户-角色-权限的关联,非常方便的进行权限管理,在这里不再说明什么是RBAC,请自行百度. 谢谢 ...

  9. nginx在线与离线安装

    1.场景描述 项目要部署到新的服务器上,需要安装nginx,刚好安全部门通知了nginx存在安全漏洞(Nginx整数溢出漏洞,nginx1.13.2之后的版本无问题),就下载最新的nginx进行了安装 ...

  10. 不可错过的几款GitHub开源项目

    工作之余或者周末感觉无聊?不知道干什么?想继续提高技术,但是不知道做什么的同学,看过来,不妨利用闲暇时间来撸几个 GitHub 上还不错的开源项目,本文推荐的开源项目比较适合新手.及对MVP设计模式不 ...