Posted by Materi Teknik Informatika • Informasi Teknologi Informasi • Digital Marketing on 9/21/2014
public class Amisabel_Tian_Chan {
public static void main(String[] args) {
for(int i=1;i<=5000;i++){
if(Amisabel(i)){
System.out.print(i+" = ");
for(int x=1;x<=i;x++){
if (i % x == 0) {
System.out.print(x);
if((i==1)||(i/x==2)) break;
if(x!=i) {
System.out.print(" + ");
}
}
}
System.out.println("");
}
}
}
public static boolean Amisabel(int x){
int tot = 0;
if(x==1) return true;
else {
for (int i=1;i<x;i++) if (x % i == 0) tot += i;
if (tot == x) return true;
else return false;
}
}
}