题目链接: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代码:

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int n[]={,,,,,,,,,,,,,,,,,,,,};
  4. char str[];
  5. int main()
  6. {
  7. int T;
  8. cin>>T;
  9. for(int kase=;kase<=T;kase++)
  10. {
  11. scanf("%s",str);
  12. int len=strlen(str);
  13. if(len>=) printf("Case #%d: %d\n",kase,n[]);
  14. else
  15. {
  16. int num=,k=;
  17. for(int i=len-;i>=;i--)
  18. {
  19. num+=(str[i]-'')*k;
  20. k*=;
  21. }
  22. printf("Case #%d: %d\n",kase,n[upper_bound(n+,n+,num)-n-]);
  23. }
  24. }
  25. }

计蒜客 31452 - Supreme Number - [简单数学][2018ICPC沈阳网络预赛K题]的更多相关文章

  1. 计蒜客 31453 - Hard to prepare - [递归][2018ICPC徐州网络预赛A题]

    题目链接:https://nanti.jisuanke.com/t/31453 After Incident, a feast is usually held in Hakurei Shrine. T ...

  2. 计蒜客31452 Supreme Number(找规律)

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

  3. 计蒜客 31447 - Fantastic Graph - [有源汇上下界可行流][2018ICPC沈阳网络预赛F题]

    题目链接:https://nanti.jisuanke.com/t/31447 "Oh, There is a bipartite graph.""Make it Fan ...

  4. 计蒜客 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 ...

  5. 计蒜客 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 ...

  6. [计蒜客] tsy's number 解题报告 (莫比乌斯反演+数论分块)

    interlinkage: https://nanti.jisuanke.com/t/38226 description: solution: 显然$\frac{\phi(j^2)}{\phi(j)} ...

  7. 计蒜客 30996 - Lpl and Energy-saving Lamps - [线段树][2018ICPC南京网络预赛G题]

    题目链接:https://nanti.jisuanke.com/t/30996 During tea-drinking, princess, amongst other things, asked w ...

  8. 计蒜客 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 ...

  9. 计蒜客 31459 - Trace - [线段树][2018ICPC徐州网络预赛G题]

    题目链接:https://nanti.jisuanke.com/t/31459 样例输入 3 1 4 4 1 3 3 样例输出 10 题意: 二维平面上给出 $n$ 个点,每个点坐标 $\left( ...

随机推荐

  1. 【转载】springboot + swagger

    注:本文参考自 http://www.jianshu.com/p/0465a2b837d2 https://www.cnblogs.com/java-zhao/p/5348113.html swagg ...

  2. UpLoader------实现上传大文件

    代码: <div id="selectFile">选择文件1</div> <script> var da = newGuid(); var kk ...

  3. AppStore应用转让流程

    可能大家都有这样的情况,给公司客户开发一个ios app的前期阶段是先发布在自己公司的开发者账户上面的,而不是直接发布在客户的开发者账号上面,这个到后期的话就有一个转让的事情,俗称“过户”. 步骤如下 ...

  4. 5 -- Hibernate的基本用法 --4 8 外连接抓取属性

    外连接抓取能限制执行SQL语句的次数来提高效率,这种外连接抓取通过在单个select语句中使用outer join来一次抓取多个数据表的数据. 外连接抓取允许在单个select语句中,通过@ManyT ...

  5. web -- 前端访问后台跨区问题解决

    package com.xindatai.ibs.web.filter; import java.io.IOException; import javax.servlet.Filter; import ...

  6. Docker background

    什么是 Docker? Docker 提供了一个可以运行你的应用程序的封套(envelope),或者说容器.它原本是 dotCloud 启动的一个业余项目,并在前些时候开源了.它吸引了大量的关注和讨论 ...

  7. win7+ oracle +php环境的搭建

    http://blog.csdn.net/chchmlml/article/details/6887326 先下载个wmpp1.7.5(之前在xp上也是这个,所以就继续),安装,一切顺利,打开phpi ...

  8. CentOS安装、配置RabbitMQ

    安装步骤(rpm包安装): rpm安装官网:http://www.rabbitmq.com/install-rpm.html 下载rpm并安装: CentOs: wget http://www.rab ...

  9. SaltStack salt-key 命令

    salt-key is used to manage Salt authentication keys [root@localhost ~]$ salt-key -L # 查看有哪些minion公钥过 ...

  10. 安装RVDS2.2

    本人经过一晚上的折腾,已经将rvds2.2成功部署在为AMD平台的CPU上面,除了些许小BUG外,编译程序无任何错误,可成功将产上的AXF文件通过Jlink烧制到开发板上. 感谢cdly7475为我们 ...