Last active
March 12, 2019 02:27
-
-
Save computingfreak/c528b650251d28d5bf997200e052a5b8 to your computer and use it in GitHub Desktop.
Godlbach's COnjecture
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
import java.lang.*; | |
import java.io.*; | |
class goldbach | |
{ | |
public static void main (String[] args) | |
{ | |
Scanner scr=new Scanner(System.in); | |
int T=scr.nextInt(); | |
scr.nextLine(); | |
for(int i=0;i<T;i++) { | |
int n=scr.nextInt(); | |
printsumpairsmall(n); | |
printsumpairlarge(n); | |
} | |
} | |
public static void printsumpairlarge(int n) { | |
int x=n/2; | |
for(int i=0;i<n/2;i++){ | |
if(isPrime(x+i)&&isPrime(x-i)){ | |
System.out.println((x+i)+" "+(x-i)); | |
break; | |
} | |
} | |
} | |
public static void printsumpairsmall(int n) { | |
int x=n/2; | |
for(int i=2;i<n/2;i++){ | |
if(isPrime(i)&&isPrime(n-i)){ | |
System.out.println((i)+" "+(n-i)); | |
break; | |
} | |
} | |
} | |
public static boolean isPrime(int n){ | |
if(n==1)return false; | |
if(n==2)return true; | |
if(n%2==0)return false; | |
for(int i=2;i<n/2;i++){ | |
if(n%i==0)return false; | |
} | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment