Interesting integers:
Number: If a number is exactly equal to the sum of his factors, it is called the completion of the number, the demand is to find out within 10000 of all the finished number.
Solution: 1. Use N to divide all the integers between 1-n, and save the dividend that can be divisible into an array as a factor of N.
2. Subtract the factor by the number n to facilitate the calculation of the sum of the factors equal to N.
3. Repeat steps 1 and 2 to find all the finished numbers.
4. Finally determine whether the sum of the factors is equal to the number n if equal, then the number of n is the end number, output the number of factors.
Package finish; public class Perfectnum {public static void main (string[] args) {int p[] = new Int[30];int count = 0;int s = 0; int c = 0;int i = 0;for (int num = 2;num <=10000;num++) {s = num;for (i =1;i<num;i++) {if (num% i = = 0) {p[count++ ] = i;s-=i;}} if (s = = 0) {System.out.printf ("%d is a complete number, factor is", num); System.out.printf ("%d =%d", num,p[0]); for (i = 1;i<count;i++) {System.out.printf ("+%d", P[i]);} System.out.println (); C + +;}}}}
Java uses data structure to solve the mathematical problem of realization problem