This article illustrates the method of jquery searching for an absolute number within N. Share to everyone for your reference. The specific analysis is as follows:
The fullness of a number depends on its factor (the number that divides the original number).
For example: The 12 factor is 1,2,3,4 and 6. When the sum of each factor of a number is greater than the number itself, the number is called the "surplus" number. So 12 is a surplus number, because its factor adds up to equal to 16. On the other hand, when the sum of the factors of a number is less than the number itself, the number is called the "deficient" number. So 10 is a deficit because its factor (1,2 and 5) adds up to only 8.
The most significant and rare numbers are those whose factors are exactly the same as their own, and the number is the perfect number.
--"Fee Martha's theorem"
Looking for a complete number, first of all to calculate the number of factors, Baidu review what is the factor.
Factor: If the integer n is divided by M, the result is an integer of the sum, then we call M the factor of N. It should be noted that only the divisor, divisor, quotient is an integer, the remainder is zero, this relationship is established. Conversely, we call n a multiple of M.
* * Find the perfect number within N * * function $ (ID) {return document.getElementById (ID);
//To determine if positive integer function isintnum (number) {var num = number;
if (!isnan (num) && (parseint (num) = parsefloat (num)) {return true;
}else{return false; } $ ("Calc"). AddEventListener ("click", Function () {var inputnum = $ ("num"). Value, $result = $ ("result"), facto
Rarr = [], Resultarr = [], i = 0, j = 0, sum = 0;
Verify that the input is a positive integer if (Isintnum (Inputnum)) {Console.log ("right");
}else{$result. InnerHTML = "Input error: Please enter a positive integer";
return false;
///Traverse all numbers for (var k = 1;k < inputnum;k++) {//each calculation needs to reset variable factorarr.length = 0;
sum = 0;
Find the factor for the current number for (i = 1;i < Math.floor (K/2) +1; i++) {if (k% i = = 0) {Factorarr.push (i);
The sum of the calculated factor for (var m = 0;m < factorarr.length;m++) {sum + = factorarr[m];
}//Factor and equal to the current number, then conform to the full number standard if (sum = = k) {Resultarr.push (k);
}} $result. Innerhtml=resultarr;
});
I hope this article will help you with your jquery programming.