31
0
We can define the Divisibility Streak k
of a number n
by finding the smallest non-negative integer k
such that n+k
is not divisible by k+1
.
Challenge
In your language of choice, write a program or function that outputs or returns the Divisibility Streak of your input.
Examples:
n=13:
13 is divisible by 1
14 is divisible by 2
15 is divisible by 3
16 is divisible by 4
17 is not divisible by 5
The Divisibilty Streak of 13
is 4
n=120:
120 is divisible by 1
121 is not divisible by 2
The Divisibilty Streak of 120
is 1
Test Cases:
n DS
2 1
3 2
4 1
5 2
6 1
7 3
8 1
9 2
10 1
2521 10
More test cases can be found here.
Notes
- Based on Project Euler Problem 601
- This sequence can be found on OEIS, shifted down by 1.
Rules
- You can assume the input is greater than 1.
Scoring
code-golf:The submission with the lowest score wins.
I suggest changing "smallest positive integer" to "smallest nonnegative integer". It doesn't change the challenge at all, but with the current description, it implies we don't need to check for divisibility by 1 (which we technically shouldn't need to). Either that, or you could remove the divisibility by 1 checks from the description. – TehPers – 2017-08-14T15:11:12.060
The smallest positive integer is 1, and
k + 1
is 2, wherek
is the smallest positive integer. Sorry for the nitpick. – TehPers – 2017-08-14T15:33:12.107Isn't this the same as finding the smallest
k
which doesn't dividen-1
? – Paŭlo Ebermann – 2017-08-14T22:28:49.037@PaŭloEbermann Take
n=7
wherek=3
:n-1
is divisible byk
. – Oliver – 2017-08-15T00:19:57.637Ah, I missed the
+1
. – Paŭlo Ebermann – 2017-08-15T16:57:16.570