6 kyu

Find Numbers with Same Amount of Divisors

298 of 915raulbc777

Description:

The integers 14 and 15 are contiguous (i.e. the difference between them is 1) and have the same number of divisors:

14 ----> 1, 2, 7, 14 # (4 divisors)
15 ----> 1, 3, 5, 15 # (4 divisors)

The next pair of contiguous integers with this property is 21 and 22:

21 -----> 1, 3,  7, 21 # (4 divisors)
22 -----> 1, 2, 11, 22 # (4 divisors)

We have 8 pairs of integers below 50 having this property, they are:

[ [2, 3], [14, 15], [21, 22], [26, 27], [33, 34], [34, 35], [38, 39], [44, 45] ]

Let's see now the integers that have a difference of 3 between them. There are 7 pairs below 100:

[ [2, 5], [35, 38], [55, 58], [62, 65], [74, 77], [82, 85], [91, 94] ]

Let's name:

  • diff, the difference between two integers, next and prev, (diff = next - prev)
  • nMax, an upper bound of the range.

We need a function that receives two integer parameters, diff and nMax, and outputs the count of pairs of integers that fulfill this property, all of them being strictly smaller than nMax.

So, for the examples detailed above:

(diff = 1, nMax =  50) -----> 8
(diff = 3, nMax = 100) -----> 7

Happy coding!!!

Algorithms
Mathematics

Stats:

CreatedSep 10, 2015
PublishedSep 10, 2015
Warriors Trained3513
Total Skips286
Total Code Submissions5623
Total Times Completed915
Python Completions298
Ruby Completions48
JavaScript Completions227
CoffeeScript Completions6
Java Completions171
C# Completions67
Clojure Completions24
Haskell Completions27
Rust Completions34
Go Completions36
C++ Completions61
Total Stars94
% of votes with a positive feedback rating92% of 203
Total "Very Satisfied" Votes175
Total "Somewhat Satisfied" Votes22
Total "Not Satisfied" Votes6
Total Rank Assessments9
Average Assessed Rank
5 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • raulbc777 Avatar
  • g964 Avatar
  • NaMe613 Avatar
  • user5036852 Avatar
  • Voile Avatar
  • bidouille Avatar
  • hobovsky Avatar
  • trashy_incel Avatar
  • akar-0 Avatar
  • Just4FunCoder Avatar
  • 66  Avatar
  • saudiGuy Avatar
Ad