Following Code will give you desired number of quark pairs:
Code:
import java.util.Scanner;
public class MainQuark {
public static void main(String[] nt) {
System.out.print("Enter Value of N :");
int n;
Scanner in=new Scanner(System.in);
n=in.nextInt();
int count=0,i=1,num;
StringBuffer buffer=new StringBuffer();
while(count!=n) {
num=i;
int q=quark(num);
if(!prime(q)) {
for(int j=num+1;j<q;j++) {
if(q==quark(j)) {
buffer.append(i+"-"+j+"\n");
count++;
}
}
}
i++;
}
System.out.println("Pairs are\n"+buffer.toString());
}
static int quark(int n) {
int one=0,i=n;
while(n>0) {
if(n%2==1) {
one++;
}n=n/2;
}return one*(i);
}
static boolean prime(int n) {
for(int i=2;i<n/2;i++) {
if(n%i==0) return false;
}return true;
}
}
Code:
import java.util.Scanner;
public class MainQuark {
public static void main(String[] nt) {
System.out.print("Enter Value of N :");
int n;
Scanner in=new Scanner(System.in);
n=in.nextInt();
int count=0,i=1,num;
StringBuffer buffer=new StringBuffer();
while(count!=n) {
num=i;
int q=quark(num);
if(!prime(q)) {
for(int j=num+1;j<q;j++) {
if(q==quark(j)) {
buffer.append(i+"-"+j+"\n");
count++;
}
}
}
i++;
}
System.out.println("Pairs are\n"+buffer.toString());
}
static int quark(int n) {
int one=0,i=n;
while(n>0) {
if(n%2==1) {
one++;
}n=n/2;
}return one*(i);
}
static boolean prime(int n) {
for(int i=2;i<n/2;i++) {
if(n%i==0) return false;
}return true;
}
}
Output: