“Integers: Recreation One” is a coding puzzle that people can be attempted in the following languages: ruby, python, javascript, java, csharp, coffeescript, haskell, clojure, cpp, php, crystal, fsharp, c, typescript, rust, swift, go, r, shell, ocaml, elixir, fortran, julia, scala, powershell, nim, purescript, reason, racket, kotlin, and prolog.
- Difficulty: 5 kyu
- Stars: 1196
- Votes: 1515
- Category: reference
- Tags: Fundamentals, Algorithms, Logic, Optimization
- Source: codewars
Description
Divisors of 42 are : 1, 2, 3, 6, 7, 14, 21, 42.
These divisors squared are: 1, 4, 9, 36, 49, 196, 441, 1764.
The sum of the squared divisors is 2500 which is 50 * 50, a square!
Given two integers m, n (1 <= m <= n) we want to find all integers
between m and n whose sum of squared divisors is itself a square.
42 is such a number.
The result will be an array of arrays or of tuples (in C an array of Pair) or a string, each subarray having two elements,
first the number whose squared divisors is a square and then the sum
of the squared divisors.
#Examples:
list_squared(1, 250) --> [[1, 1], [42, 2500], [246, 84100]]
list_squared(42, 250) --> [[42, 2500], [246, 84100]]
The form of the examples may change according to the language, see Example Tests:
for more details.
Note
In Fortran - as in any other language - the returned string is not permitted to contain any redundant trailing whitespace: you can use dynamically allocated character strings.
Solve It Here
Click the link below to solve it on Codewars:
Notes
This puzzle was posted by a Slackbot via a slash command. If you want to help work on the app, send a message to @Josh.
If you don’t want to see the coding puzzles when you visit the forum, you can go into your settings and mute the puzzles category.