Answer to Question #199562 in HTML/JavaScript Web Application for ravi

Question #199562

Lucky Pairs

Write Java script program to count the number of lucky pairs.

Two numbers are said to be lucky pairs . if first number is divided by second number and second number is divided by first number. given an integer N . find all possible combinations of lucky pairs.



input:

2


output:

2


Explanation:

input is 2

possible combinations are [1,2],[2,1].here in [1,2]1 is divisible by 2, and in [2,1] 2 is divisible by 1 .so the number of lucky pairs are 2.



1
Expert's answer
2021-05-27T19:09:05-0400
<spript>
  const n; // length of the arr below
  let arr;
  let count = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i != j and i % j == 0) {
        count += 1;
      }
    }
  }
  console.log(2*count);
</script>

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS