素数距离问题
来源:互联网 发布:mac qq 讨论组 删除人 编辑:程序博客网 时间:2024/06/04 01:39
import java.util.Scanner;
public class acm24 {
public static boolean judge(int a){
boolean flag=true;
if(a<2){
return false;
}
else{
for(int i=2;i<=Math.sqrt(a);i++){
if(a%i==0){flag=false;break;}
}
}
return flag;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input=new Scanner (System.in);
int f=input.nextInt();
while(f>0&&f<=10000){
Scanner input1=new Scanner (System.in);
int f1=input1.nextInt();
int m=f1,n=f1;
if(judge(f1)==true){
System.out.print(f1);
System.out.print(' ');
System.out.println(0);
}
else
{
boolean is=true;
while(is){
n--;
m++;
if(judge(n)==true&&judge(m)!=true||judge(n)==true&&judge(m)==true){
System.out.print(n);
System.out.print(' ');
System.out.println((f1-n));is=false;
}
if(judge(n)!=true&&judge(m)==true){
System.out.print(m);
System.out.print(' ');
System.out.println((m-f1));is=false;
}
}
}
--f;
}
}
}
public class acm24 {
public static boolean judge(int a){
boolean flag=true;
if(a<2){
return false;
}
else{
for(int i=2;i<=Math.sqrt(a);i++){
if(a%i==0){flag=false;break;}
}
}
return flag;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input=new Scanner (System.in);
int f=input.nextInt();
while(f>0&&f<=10000){
Scanner input1=new Scanner (System.in);
int f1=input1.nextInt();
int m=f1,n=f1;
if(judge(f1)==true){
System.out.print(f1);
System.out.print(' ');
System.out.println(0);
}
else
{
boolean is=true;
while(is){
n--;
m++;
if(judge(n)==true&&judge(m)!=true||judge(n)==true&&judge(m)==true){
System.out.print(n);
System.out.print(' ');
System.out.println((f1-n));is=false;
}
if(judge(n)!=true&&judge(m)==true){
System.out.print(m);
System.out.print(' ');
System.out.println((m-f1));is=false;
}
}
}
--f;
}
}
}
阅读全文
0 0
- 素数距离问题
- NYOJ - 素数距离问题
- 素数距离问题
- NYOJ24-素数距离问题
- 素数距离问题
- 素数距离问题
- 素数距离问题
- 【素数距离问题 24】
- 素数距离问题
- 素数距离问题
- 素数距离问题
- 素数距离问题
- nyoj24素数距离问题
- nyoj24 素数距离问题
- NYOJ24 素数距离问题
- 素数距离问题
- 素数距离问题
- 素数距离问题
- nginx无法解析php文件,出现502错误
- Eclipse导入git工程(HTTP与SSH两种导入方式)
- Java修饰符大汇总
- SAX解析XML
- InfluxDB学习之InfluxDB的基本操作
- 素数距离问题
- win7x64下的redis安装与使用
- 【科普】VoLTE到底是什么?来普及一下 这个好技术
- 懒加载之jQuery图片延迟加载插件jQuery.lazyload
- Mybatis的一级缓存和二级缓存
- memcached 以及 session-server部署
- kylin : killed by admin
- NIO ServerSocketChannel
- DialogFragment的简单使用