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[] quarks=new int[n];
int num=0;
for(int i=0;i<n;i++) {
num=i+1;
int one=0;
while(num>0) {
if(num%2==1) {
one++;
}num=num/2;
}
quarks[i]=one*(i+1);
}
StringBuffer buffer=new StringBuffer();
for(int i=0;i<n;i++) {
for(int j=i+1;j<n;j++) {
if(quarks[i]==quarks[j]) {
buffer.append((i+1)+"-"+(j+1)+"\n");
}
}
}
System.out.println("All Pairs upto "+n+" : ");
System.out.println(buffer.toString());
}
}
Output: