当前位置:网站首页>Acwing summer daily question (sexy prime number on June 10)
Acwing summer daily question (sexy prime number on June 10)
2022-06-12 15:16:00 【Dashuaibi's junior attendant】
“ Sexy prime ” It is shaped like (p,p+6)(p,p+6) Such a pair of prime numbers .
It's called , Because the Latin tube “ 6、 ... and ” It's called “sex”( That is, English “ sexy ”).
Now give an integer , Please judge whether it is a sexy prime .
Input format
Input gives a positive integer on a line NN.
Output format
if NN It's a sexy prime , Output in one line Yes
, And output and on the second line NN Another sexy prime paired ( If such a number is not unique , The one with the smaller output ).
if NN Not a sexy prime , Output in one line No
, Then output greater than... On the second line NN The minimum number of sexy prime .
Data range
1≤N≤10^8
Their thinking : First, use trial division to screen prime numbers . If it's a sexy prime number , Output “Yes” And sexy prime , If not , Then violence goes to the nearest sexy prime number , guess : The nearest one must not be far away . If possible Ac Just go , Otherwise, it needs to be optimized .
Code :
import java.util.*;
import java.io.*;
public class Main{
public static boolean is_prime(int n){
if(n <= 2){
return false;
}
for(int i = 2 ; i <= n / i ; i++){
if(n % i == 0){
return false;
}
}
return true;
}
public static void main(String args[]) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
for(int i = n - 6 ; i <= n + 6 ; i += 12){
if(is_prime(i) && is_prime(n)){
System.out.println("Yes");
System.out.println(i);
return;
}
}
for(int i = n + 1 ;; i++){
if(is_prime(i) && (is_prime(i-6) || is_prime(i+6))){
System.out.println("No");
System.out.println(i);
return;
}
}
}
}
summary :
I haven't written algorithms for a long time , I / O is jammed , Hands are too raw , Adhere to the
边栏推荐
- Notes on ARM 64 instructions
- Change according to the situation, the road to promotion in the second half of 2022
- Autofac Beginner (1)
- Apprendre est une chose contre la nature humaine
- Selenium advanced
- 产业端:618的新战场
- New features of ES6
- C constant, cannot be changed
- Qiming Zhixian shares the application scheme of 2.8-inch handheld central control screen
- ROS 中 boost::bind( ) 的使用
猜你喜欢
[wp][beginner level] attack and defense world game
Xshell 7 official website free download
Seaborn的简述
3D reconstruction system | L3 dual view motion recovery structure (SFM binocular SFM)
Deepin20.6 rtx3080 installer le lecteur de carte graphique 510.60.02, cuda 11.6, pytorch1.11
SOA Architecture
Servlet连接数据库实现用户登录功能
C 操作符
Selenium advanced
Pta: self test -2 prime pair conjecture (20 points)
随机推荐
C main函数
Element positioning of selenium
Array related content
[jvm learning] local method stack and heap
Seaborn的简述
Autofac Beginner (1)
Servlet连接数据库实现用户登录功能
ROS 中 boost::bind( ) 的使用
TCP/IP 三次握手四次挥手(面试题)
C constant, cannot be changed
阿里、腾讯、拼多多垂范,产业互联网的新逻辑渐显
C 操作符
Tcp/ip three handshakes and four waves (interview questions)
idea 拉取分支代码
ROS中tf学习笔记
Left aligned, right aligned, random number, goto, compare output bool
odom坐标系的理解
[SPARK][CORE] 面试问题之谈一谈Push-based shuffle
Kinect2.0+ORBSLAM2_with_pointcloud_map
简单的爬虫框架:解析51job页面岗位信息