The complete number (Perfect number), also known as the perfect or complete number, is a special natural number. The sum of all its true factors (that is, divisors other than itself) and (that is, the factor function) is exactly equal to itself.
Dim A as integer,b as integer,c as Integer for
a = 1 to 10000
c = 0 for
B = 1 to a \ 2
If a Mod b = 0 Then c = C + b
next b
If a = c Then Print Str (a)
next
Attach the Java version of the code
Import java.util.ArrayList;
public class T013 {public
static void Main (string[] args) {
ArrayList p = new ArrayList ();//save decomposition Factor
int Co for each group UNT = 0; Count (total number of ends)
int sum; sum = (and per factor) for
(int i=2;i<10000;i++) { //test each number i
sum = 0;
for (int j=1;j<i/2+1;j++) {
if (i%j==0) {
p.add (j); Save I for each factor
sum = j; Save sum (all factor of I Plus and)
}
}
if (sum==i) { //If the current I is finished, output (i= all factor sum)
count++;
System.out.printf ("%4d" + "is the end of the number, the factor is" +i+ "=", i);
for (int k=0;k<p.size () -1;k++) {
System.out.print (P.get (k) + "+");
}
System.out.println (P.get (P.size ()-1));
}
P.clear (); Each I ends, empties the array, and the next I factor is weighed.
}
System.out.println ("\ n Find the +count+"!) ");
}
The above mentioned is the entire content of this article, I hope you can enjoy.