java speed
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int b=sc.nextInt();
while(a!=0||b!=0) {
perfect(a,b);
amicable(a,b);
a=sc.nextInt();
b=sc.nextInt();
}
sc.close();
}
static int fSum(int n) {
int sum=0;
for(int i=1;i<Math.sqrt(n);i++) {
if(n%i==0) {
sum+=i+n/i;
}
}
return sum-n;
}
static void perfect(int start,int end) {
if(start>end) {
int t=start;
start=end;
end=t;
}
for(int i=start;i<=end;i++) {
if(fSum(i)==i) {
System.out.print(i+" ");
}
}
System.out.println();
}
static void amicable(int start,int end) {
if(start>end) {
int t=start;
start=end;
end=t;
}
for(int i=start;i<=end;i++) {
int j=fSum(i);
if(fSum(j)==i&&i<j) {
System.out.print(i+","+j+" ");
}
}
System.out.println();
}
}