Supreme Number

  • 1000ms
  • 131072K
 

A prime number (or a prime) is a natural number greater than 111 that cannot be formed by multiplying two smaller natural numbers.

Now lets define a number NNN as the supreme number if and only if each number made up of an non-empty subsequence of all the numeric digits of NNN must be either a prime number or 111.

For example, 171717 is a supreme number because 111, 777, 171717 are all prime numbers or 111, and 191919 is not, because 999 is not a prime number.

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

Input

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

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

Output

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

样例输入

2
6
100

样例输出

Case #1: 5
Case #2: 73
 #include<bits/stdc++.h>
using namespace std;
int main()
{
int a[] = {,,,,,,,,,,,,,,,,,,,
};
int s;
int t,count = ;
cin >> t;
while(t--)
{
cin >> s;
cout << "Case #" << count++ << ": " ;
if(s >= )
{
cout << a[] << endl;
continue;
}
else
{
for(int i = ; i >= ; i --)
{
if(s >= a[i])
{
cout << a[i] << endl;
break;
}
}
}
}
return ;
}

ACM-ICPC 2018 沈阳赛区网络预赛的更多相关文章

  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

    Supreme Number A prime number (or a prime) is a natural number greater than 11 that cannot be formed ...

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

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

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

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

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

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

  8. Fantastic Graph 2018 沈阳赛区网络预赛 F题

    题意: 二分图 有k条边,我们去选择其中的几条 每选中一条那么此条边的u 和 v的度数就+1,最后使得所有点的度数都在[l, r]这个区间内 , 这就相当于 边流入1,流出1,最后使流量平衡 解析: ...

  9. ACM-ICPC 2018 沈阳赛区网络预赛 F Fantastic Graph(贪心或有源汇上下界网络流)

    https://nanti.jisuanke.com/t/31447 题意 一个二分图,左边N个点,右边M个点,中间K条边,问你是否可以删掉边使得所有点的度数在[L,R]之间 分析 最大流不太会.. ...

  10. ACM-ICPC 2018 沈阳赛区网络预赛 B Call of Accepted(表达式求值)

    https://nanti.jisuanke.com/t/31443 题意 给出一个表达式,求最小值和最大值. 表达式中的运算符只有'+'.'-'.'*'.'d',xdy 表示一个 y 面的骰子 ro ...

随机推荐

  1. VB错误说明

    1001 800A03E9 内存不足 1002 800A03EA 语法错误 1003 800A03EB 缺少“:” 1005 800A03ED 需要 '(' 1006 800A03EE 需要 ')' ...

  2. php计算上个月是几月份

    PHP计算上个月的时间, $date = date("Y-m-d"); $arr = explode('-',$date); foreach ($arr as $key=>$ ...

  3. Delphi XE10.1 引用计数

      以往的Delphi版本,不支持接口的Weak,和UnSafe的引用,支持对象的Weak, UnSafe,而且仅在Android和Ios平台上支持. 现在Delphi XE10.1 Berlin终于 ...

  4. laravel5实现微信第三方登录功能

    背景 最近手头一个项目需要实现用户在网站的第三方登录(微信和微博),后端框架laravel5.4. 实现过程以微信网页版第三方登录,其他于此类似,在此不做重复. 准备工作 网站应用微信登录是基于OAu ...

  5. 双端队列 ADT接口 数组实现

    Deque ADT接口 DEQUEUE.h: #include <stdlib.h> #include "Item.h" void DEQUEUEinit(int); ...

  6. Hadoop学习总结之Map-Reduce的过程解析

    一.客户端 Map-Reduce的过程首先是由客户端提交一个任务开始的. 提交任务主要是通过JobClient.runJob(JobConf)静态函数实现的: public static Runnin ...

  7. Java程序设计 第16周 课堂实践 —— 数据库3

    Java程序设计 第16周 课堂实践 -- 数据库3 课堂实践任务3 查询world数据库,获得New Jessey州所有城市的总人口数. 代码分析 实现查询数据库需要我们修改MessageDAO.j ...

  8. 20155222 2016-2017-2 《Java程序设计》实验三

    20155222 2016-2017-2 <Java程序设计>实验三 1 在IDEA中使用工具(Code->Reformate Code)把下面代码重新格式化,再研究一下Code菜单 ...

  9. 20155236 2016-2017-2 《Java程序设计》第十周学习总结

    20155236 2016-2017-2 <Java程序设计>第十周学习总结 教材学习内容总结 网络编程就是在两个或两个以上的设备(例如计算机)之间传输数据. 程序员所作的事情就是把数据发 ...

  10. 20155315 2016-2017-2 《Java程序设计》第十周学习总结

    学习目标 了解计算机网络基础 掌握Java Socket编程 理解混合密码系统 掌握Java 密码技术相关API的使用 学习资源 Java和Android开发学习指南(第二版)(EPUBIT,,Jav ...