Skip to content

Instantly share code, notes, and snippets.

@computingfreak
Last active March 12, 2019 02:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save computingfreak/c528b650251d28d5bf997200e052a5b8 to your computer and use it in GitHub Desktop.
Save computingfreak/c528b650251d28d5bf997200e052a5b8 to your computer and use it in GitHub Desktop.
Godlbach's COnjecture
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