This article is about the solution of the complete number, here I want to say is the idea of this code, because to implement this function, it is really not difficult, the total number, that is, all the factors are added equal to this number, then this number is called the complete number, the idea in this code is in a range, each time traversing a number, Then save two times this number, one for the factor, the other for whether the last and 0, feeling if it is the first time I think, should be unexpected.
Code:
Package Com.jk.perfectdemo;
Import Java.util.Arrays;
/**
*
* @author JK, this code is written to complete the number of solutions, the total number is the factor is equal to the number of the number, the code is not much, but I think it can also, so I wrote
* * */public
class test {
/**
* @param args
*
/public static void main (string[] args) {
//Find the complete number within 5000
perfectnum ( 5000);
}
private static void Perfectnum (int rangge) {
long[] p=new long[300];
Long I,j,sum,num;
int k,count;
Iterate through each number for
(i=0;i<rangge;i++) {
count=0;
num=i;
Sum=num;
See if each number conforms to the full number of conditions for
(j=1;j<num;j++) {
if (num%j==0) {
p[count++]=j;
Sum=sum-j
}
}
if (sum==0) {
System.out.println (num+ "=" +arrays.tostring (p));}}}