#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
using namespace std;
bool visit[];
int prime[]; void init_prim()
{
memset(visit, true, sizeof(visit));
int num = ;
for (int i = ; i <= ; ++i)
{
if (visit[i] == true)
{
num++;
prime[num] = i;
}
for (int j = ; ((j <= num) && (i * prime[j] <= )); ++j)
{
visit[i * prime[j]] = false;
if (i % prime[j] == ) break;
}
}
}
int main() {
memset(prime, , sizeof(prime));
int T, n;
init_prim();
scanf("%d", &T);
while(T--) {
scanf("%d", &n);
bool flag = true;
if(n < 1e6) {
if(n == ) {
printf("%d\n", );
} else if(visit[n] == true){
printf("%d\n", n-);
} else {
printf("%d\n", );
}
} else {
for(int i = ; prime[i] <= sqrt(n); ++i) {
if(n % prime[i] == ) {
flag = false;
printf("%d\n", );
break;
}
}
if(flag) {
printf("%d\n", n-);
}
}
}
return ;
}

第一题

BestCoder#51的更多相关文章

  1. Spring Boot文档

    本文来自于springboot官方文档 地址:https://docs.spring.io/spring-boot/docs/current/reference/html/ Spring Boot参考 ...

  2. 判素数+找规律 BestCoder Round #51 (div.2) 1001 Zball in Tina Town

    题目传送门 /* 题意: 求(n-1)! mod n 数论:没啥意思,打个表能发现规律,但坑点是4时要特判! */ /***************************************** ...

  3. BestCoder Round #51 (div.2)

    明显是无良心的数学round= = 1000 Zball in Tina Town #include<iostream> #include<cstdio> #include&l ...

  4. hdu 5636 搜索 BestCoder Round #74 (div.2)

    Shortest Path  Accepts: 40  Submissions: 610  Time Limit: 4000/2000 MS (Java/Others)  Memory Limit: ...

  5. BestCoder Round#15 1001-Love

    http://acm.hdu.edu.cn/showproblem.php?pid=5082 Love Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  6. 记一次jdk升级引起的 Unsupported major.minor version 51.0

    之前jdk 一直是1.6,tomcat 是6.x 版本,, 现在引入的新的jar, 出现 Caused by: java.lang.UnsupportedClassVersionError: org/ ...

  7. 编写高质量代码:改善Java程序的151个建议(第3章:类、对象及方法___建议47~51)

    建议47:在equals中使用getClass进行类型判断 本节我们继续讨论覆写equals的问题,这次我们编写一个员工Employee类继承Person类,这很正常,员工也是人嘛,而且在JavaBe ...

  8. Bestcoder#5 1002

    Bestcoder#5 1002 Poor MitsuiTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (J ...

  9. 解决Unsupported major.minor version 51.0错误

    解决Unsupported major.minor version 51.0错误使用jdk6运行项目时发生了Unsupported major.minor version 51.0错误.经过网上搜索发 ...

随机推荐

  1. Hibernate之缓存的原理

    一.关于缓存: 其实对于缓存而言,它其实就是一块内存空间,在这个空间中存放了相互关联的持久化对象, 也就是存在于Session缓存内的对象,那么Session负责根据持久化对象的状态变化来同步的更新数 ...

  2. 双向数据绑定(angular,vue)

    最近github上插件项目更新了关于双向数据绑定的实现方式,关于angular和vue. angular众所周知是使用的脏检查($dirty).一开始大家会认为angular开启了类似setInter ...

  3. jquery 中jsonp的实现原理

    在同源策略下,在某个服务器下的页面是无法获取到该服务器以外的数据的,即一般的 ajax是不能进行跨域请求的.但 img.iframe .script等标签是个例外,这些标签可以通过 src属性请求到其 ...

  4. BZOJ 2160: 拉拉队排练

    Description 问长度前 \(k\) 大的奇长度回文子串的乘积. Sol Manacher. 直接马拉车跑一边,统计一下答案,每次将长度-2就可以了. Code /************** ...

  5. Kali 开机报错解决方案

    问题一: piix4_smbus ::007.3: Host SMBus controller not enabled 解决:打开 /etc/modprobe.d/blacklist.conf 末尾加 ...

  6. ORA-00257: archiver error. Connect internal only, until freed.

    早上BA抄送客户的邮件过来,说系统用不了,应用系统报异常Unable to open connection to oracle,Microsoft Provider v2.0.50727.42,既然是 ...

  7. Python全栈开发【模块】

    Python全栈开发[模块] 本节内容: 模块介绍 time random os sys json & picle shelve XML hashlib ConfigParser loggin ...

  8. 点击页面判断是否安装app并打开,否则跳转app store的方法

    常常有这样的场景,咱们开发出来的APP需要进行推广,比如在页面顶部来一张大Banner图片,亦或一张二维码.但往往我们都是直接给推广图片加了一个下载链接(App Store中的).所以咱们来模拟一下用 ...

  9. remove mysql

    apt-get --purge remove mysql-server mysql-client mysql-common apt-get autoremove rm -rf /etc/mysql r ...

  10. maven打包

    1.利用maven-jar-plugin <build> <plugins> <!-- The configuration of maven-jar-plugin --& ...