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 ...
随机推荐
- Ubuntu12.04下安装Subversion并进行配置
Ubuntu下安装Subversion还是很简单的,只要输入sudo apt-get install Subversion就可以安装了. 主要的难点在于对权限的配置上. 安装完subversion后, ...
- Ubuntu12.04安装MariaDB并修改字符集为UTF-8
其实按照MariaDB官网的步骤来安装MariaDB特别的简单,只要按照步骤来做,很容易就搞定了. 首先,到MariaDB官网: https://downloads.mariadb.org/maria ...
- vue 使用 computed 结合 filter 实现数据的的过滤和排序
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- jvm学习(5) 对象的创建与结构
上图表明:jvm虚拟机位于操作系统的堆中,并且,程序员写好的类加载到虚拟机执行的过程是:当一个classLoder启动的时候,classLoader的生存地点在jvm中的堆,然后它会去主机硬盘上将A. ...
- python学习第十天列表的增加,修改,删除操作方法
在一个有序的数据列表中,集各种数据类型,可以向列表增加元素,也可以修改列表里面的元素,可以删除列表的里面元素,append(),insert(),remove(),pop(),和全局DEL 删除等. ...
- Nexus搭建Maven私服中央仓库
一.概述 1.概要 现在的项目基本都是用Maven来管理工程,这样一来在公司内容搭建一个私服就非常有必要了,这样一来可以管理公司内部用的JAR包,也可以管理第三方的各种JAR来,以免每次都要从外网的仓 ...
- Codeforces Round #554 (Div. 2) C.Neko does Maths (gcd的运用)
题目链接:https://codeforces.com/contest/1152/problem/C 题目大意:给定两个正整数a,b,其中(1<=a,b<=1e9),求一个正整数k(0&l ...
- Linux --忘记root密码/su: Authentication failure
如果忘记了root用户的密码,或者su root的时候,提示:su: Authentication failure 那么,可以通过以下的方式来重新设置密码,而后,再尝试,那么就可以顺利su root了 ...
- JVM内存组成
JVM的内存区域模型 1.方法区 也称永久代.非堆. 用于存储虚拟机加载的类信息.常量.静态变量,是各个线程共享的内存区域. 默认最小值为16MB,最大值为64MB,可以通过-XX:PermSize和 ...
- CenterOS 7安装Nginx
1.wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm下载对 ...