jquery search for a method of N-within-complete numbers _jquery

Source: Internet
Author: User

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.

<! DOCTYPE html> 
 
 
* * 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.