- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing

- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM

- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers

- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources

# Integers have sum of squared divisors as perfect square in JavaScript

## Problem

We are required to write a JavaScript function that takes in a range specified by an array of two numbers m and n.

Our function is supposed to find all integers between m and n (m and n integers such as 1 <= m <= n) such that the sum of their squared divisors is itself a square.

It should return an array of subarrays. The subarrays will have two elements: first the number the squared divisors of which is a square and then the sum of the squared divisors.

## Example

Following is the code −

const range = [1, 500]; const listSquared = ([m, n]) => { const res = []; for (let i = m; i <= n; ++i) { let sum = getDivisors(i).reduce((sum, n) => sum + n * n, 0); let ok = Number.isInteger(Math.sqrt(sum)); if (ok) { res.push([i, sum]); } } return res; } function getDivisors (n) { const divisors = []; for (let i = 1; i <= n / 2; ++i) { if (n % i) { continue; } divisors.push(i); } return divisors.concat([n]); } console.log(listSquared(range));

## Output

[ [ 1, 1 ], [ 42, 2500 ], [ 246, 84100 ], [ 287, 84100 ] ]

- Related Articles
- Squared and square rooted sum of numbers of an array in JavaScript
- Squared sum of n odd numbers - JavaScript
- Check for perfect square in JavaScript
- Building an array of specific size with consecutive element sum being perfect square in JavaScript
- Difference between sum of square and square of sum in JavaScript
- Count all perfect divisors of a number in C++
- Divisors of n-square that are not divisors of n in C++ Program
- JavaScript Program to Generate a matrix having sum of secondary diagonal equal to a perfect square
- Minimum number of Square Free Divisors in C++
- Count the numbers < N which have equal number of divisors as K in C++
- Count of pairs in an array whose sum is a perfect square in C++
- Can we have integers as elements of an enum in Java?
- Is a number sum of two perfect squares in JavaScript
- Find sum of divisors of all the divisors of a natural number in C++
- C Program to find sum of perfect square elements in an array using pointers.

Advertisements