upc组队赛15 Supreme Number【打表】
Supreme Number
题目链接
题目描述
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≤10100), could you find the maximal supreme number that does not exceed N?
输入
In the first line, there is an integer T(T≤100000) indicating the numbers of test cases.
In the following T lines, there is an integer N (2≤N≤10100).
输出
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
题解
通过打表发现满足条件的最大数为317
坑点在于石油大把10^100写成10100
代码
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define scac(x) scanf("%c",&x)
#define sca(x) scanf("%d",&x)
#define sca2(x,y) scanf("%d%d",&x,&y)
#define sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define scl(x) scanf("%lld",&x)
#define scl2(x,y) scanf("%lld%lld",&x,&y)
#define scl3(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
#define pri(x) printf("%d\n",x)
#define pri2(x,y) printf("%d %d\n",x,y)
#define pri3(x,y,z) printf("%d %d %d\n",x,y,z)
#define prl(x) printf("%lld\n",x)
#define prl2(x,y) printf("%lld %lld\n",x,y)
#define prl3(x,y,z) printf("%lld %lld %lld\n",x,y,z)
#define ll long long
#define LL long long
#define pb push_back
#define mp make_pair
#define P pair<int,int>
#define PLL pair<ll,ll>
#define PI acos(1.0)
#define eps 1e-6
#define inf 1e17
#define INF 0x3f3f3f3f
#define MOD 998244353
#define mod 1e9+7
#define N 1000005
const int maxn=10000;
// int prime[1000100]; //打表程序
// bool book[1000100];
// int top;
// void isprime()
// {
// memset(book, true, sizeof(book));
// book[1] = false;
// for(int i=2;i<maxn;i++)
// {
// if(book[i])
// {
// for(int j=i+i;j<maxn;j+=i)
// {
// book[j] = false;
// }
// }
// }
// for(int i=2;i<=maxn;i++)
// {
// if(book[i])
// {
// prime[++top] = i;
// }
// }
// }
// int main()
// {
// int n;
// isprime();
// book[1] = true;
// for(int i = 10000; i >= 1000;i--)
// {
// if(book[i])
// {
// int temp = i;
// int a = temp%10;
// temp/=10;
// int b = temp%10;
// temp/=10;
// int c = temp%10;
// temp /=10;
// int d = temp;
// printf("%d %d %d %d\n",d,c,b,a);
// if(book[a] && book[b] && book[c] && book[d] && book[d*10+c] && book[d*10+b] && book[d*10+a] && book[c*10 + b] && book[c*10 + a] && book[b*10 + a] && book[d*100 + c*10 +b] && book[d*100 + c*10 +a] && book[d*100 + b*10 +a] && book[c*100 + b*10 +a])
// {
// printf("%d\n",i);
// }
// }
// }
// }
int a[100] = {1,2,3,5,7,11,13,17,23,31,37,53,71,73,113,131,137,173,311,317,10101};
int main()
{
int n;
int t;
sca(t);
int cas = 1;
string s;
while(t--)
{
// sca(n);
n = 0;
cin>>s;
if(s.length()>4)
{
printf("Case #%d: %d\n",cas++,317);
continue;
}
rep(i,0,s.length())
{
n = n*10+s[i]-'0';
}
rep(i,0,21)
{
if(n<a[i])
{
printf("Case #%d: %d\n",cas++,a[i-1]);
break;
}
}
}
return 0;
}
upc组队赛15 Supreme Number【打表】的更多相关文章
- upc组队赛15 Lattice's basics in digital electronics【模拟】
Lattice's basics in digital electronics 题目链接 题目描述 LATTICE is learning Digital Electronic Technology. ...
- upc组队赛15 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 ...
- 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 ...
- 15、oracle多表查询
15.0.实验建表: --父表 create table class( id number(10)constraint class_id_pk primary key, class_name varc ...
- 15.5 自学Zabbix之路15.5 Zabbix数据库表结构简单解析-其他 表
点击返回:自学Zabbix之路 自学Zabbix之路15.5 Zabbix数据库表结构简单解析-其他 表 1. Actions表 actions表记录了当触发器触发时,需要采用的动作. 2.Aler ...
- 计蒜客31452 Supreme Number(找规律)
A prime number (or a prime) is a natural number greater than 11 that cannot be formed by multiplying ...
- 自学Zabbix之路15.1 Zabbix数据库表结构简单解析-Hosts表、Hosts_groups表、Interface表
点击返回:自学Zabbix之路 点击返回:自学Zabbix4.0之路 点击返回:自学zabbix集锦 自学Zabbix之路15.1 Zabbix数据库表结构简单解析-Hosts表.Hosts_grou ...
- 自学Zabbix之路15.2 Zabbix数据库表结构简单解析-Items表
点击返回:自学Zabbix之路 点击返回:自学Zabbix4.0之路 点击返回:自学zabbix集锦 自学Zabbix之路15.2 Zabbix数据库表结构简单解析-Items表 Items表记录了i ...
- 自学Zabbix之路15.3 Zabbix数据库表结构简单解析-Triggers表、Applications表、 Mapplings表
点击返回:自学Zabbix之路 点击返回:自学Zabbix4.0之路 点击返回:自学zabbix集锦 自学Zabbix之路15.3 Zabbix数据库表结构简单解析-Triggers表.Applica ...
随机推荐
- BFS+打印路径
题目是给你起点sx,和终点gx:牛在起点可以进行下面两个操作: 步行:John花一分钟由任意点X移动到点X-1或点X+1. 瞬移:John花一分钟由任意点X移动到点2*X. 你要输出最短步数及打印路径 ...
- qt 如何使用私有类?
在模块后面加上 -private 关键字,例如 widgets-private 然后 qmake 让配置文件运行一下. 在使用 QStackedLayout 布局并设置 QStackedLayout: ...
- nginx的4层负载均衡配置
前言:所谓四层就是基于IP+端口的负载均衡:七层就是基于URL等应用层信息的负载均衡:同理,还有基于MAC地址的二层负载均衡和基于IP地址的三层负载均衡. 换句换说,二层负载均衡会通过一个虚拟MAC地 ...
- Windows程序设计(七)--鼠标
7.2 客户区鼠标消息 当鼠标移过窗口的显示区域时,窗口消息处理程序收到WM_MOUSEMOVE消息.当在窗口的显示区域中按下或者释放一个鼠标按键时,窗口消息处理程序会接收到下面这些消息: 键 按下 ...
- 请列举出JS对象的几种创建方式?
javascript创建对象简单的说,无非就是使用内置对象或各种自定义对象,当然还可以用JSON:但写法有很多种,也能混合使用. 1.对象字面量的方式 var person={firstname:&q ...
- vue,一路走来(14)--短信验证码框的实现(类似支付密码框)
由于项目的扩展,新增了很多功能,今天谈一下短信验证码框的实现. 思路:每个小方框其实就是单独的每一个input标签(叫假input标签),每个长度为1,然后上面再写一个大的input标签(叫真实inp ...
- Linux使用rarcrack暴力破解RAR,ZIP,7Z压缩包
1.下载http://rarcrack.sourceforge.net/ 2.安装依赖 gcc libxml2-devel libxslt-devel 3.使用rarcrack your_encry ...
- ElasticSearch java api -单例模式
//单例模式 private static Settings getSettingInstance(){ if(settings==null){ synchronized (Settings.clas ...
- ThinkPHP import 类库导入 include PHP文件
ThinkPHP 模拟了 Java 的类库导入机制,统一采用 import 方法进行类文件的加载.import 方法是 ThinkPHP 内建的类库和文件导入方法,提供了方便和灵活的文件导入机制,完全 ...
- TensorFlow学习笔记(一)
光复制几个代码到自己机器上跑是没有用的.要理解!公式理解有困难,就用图片辅助理解! MNIST中数字的表示方法 什么是one-hot? "One-hot" encoding mea ...