Amazon Interview Question
Software Engineer / DevelopersN(N^2-1)=(N-1)N(N+1)
means it must be divisible by 2 and 3(Why?)
since 24=2X2X2X3
so N(N^2-1) is divisible by 24.
for odd Ns,
(N-1) - is even, so div by 2 (smallest is 2)
N is odd
(N+1) - is even, next num div by 2 (smallest is 4=2x2)
N(N+1) is div by 3
So, 2x 2x2 x3 = 24 is a factor
is it guaranteed that if n is odd then n(n+1) is divisible by 3 ?
wat abt n=7
(7-1) x 7 x (7+1) = 6 x 7 x 8
here, 7x8 = 56 % 3 = 2.. so ur assumption is not true
Let p = n*(n^2-1) = (n-1) n (n+1). Being product of 3 consecutive numbers, p is divisible by 3.
Also as n is odd, let n = 2k+1; then p = (2k) (2k + 1)( 2k + 2) = 4k(k+1)(2k+1). As k and k+ 1 are two consecutive numbers so it is divisible by 2 and hence p is divisible by 8.
As 3 and 8 are co-prime, p is divisible by 3*8 = 24.
what do u mean: n*(n^2 - 1) is div by always?
if so, n = 4 and result = 60.
correct the question
n(n^2-1) = n(n-1)(n+1)
24 = 1*2*2*2*3
Out n, n-1, n+1 two are definitely even. They are divided out by two 2's in 24s.
Remaining is 6.
Out of n, n-1, n+1, one is definitely divisible by 3. That number is divided by the 3 in 24.
Now out of the two even numbers in n, n-1, n+1 one is double of one odd number, and one is definitely double of one even number.
So that number is divided out by the remaining 2. Rest remaining is 1. Thus dividable
n(n^2-1) -> (n-1)n(n+1)----eq.1
24 = 2*3*4---eq.2
suppose we assume that eq.1 is divisible by 24, now next odd n would be n+2 representing eq.1 as
(n+1)(n+2)(n+3)
suppose we add the same factor to eq.2 then it becomes 4*5*6->120 which is also divisble by 24 and represents 5 in equation 1
i am not sure if it the correct proof
n(n^2-1) can be written as (n-1)*n*(n+1)
1) that means it will always be divisible by 3 (because one of the three contiguous number must be multiple of 3)
2) n is odd and >=3 that means it can be 2*3*4, 4*5*6, 6*7*8 .....
So it can be clearly seen that one of the (n-1) and (n+1) will be divisible by 2 and other by 4 for sure.{n-1 & n+1 are two continuous even numbers}
By 1) and 2) we can clearly say that (n-1)*n*(n+1) will always be divisible by 24 (3*2*4).
P = n*(n^2-1) = (n-1)*n*(n+1)
let, n = 2m+1 (n being odd)
We have, P = (2m)*(2m+1)*(2m+2) = 4*m*(m+1)*(2m+1)
Now, the formula for sum of squares of integers as:
S = 1^2 + 2^2 + ... + m^2 = [m*(m+1)*(2m+1)]/6
Therefore, m*(m+1)*(2m+1) = 6S
Hence we have, P = 4*6S = 24S
Man, do Amazon ask so simple questions in round 3????
There could be many methods, as explained in previous post.....
n*(n^2-1) = n(n+1)(n-1)
(1) when n is 'odd'; (n+1) and (n-1) are even. We get 2*2*2 from this, since n>3
(2) n, n-1, n+1 are consecutive, so one has to be multiple of 3.
From 1 and 2, we get 2*2*2*3=24
this only works when N is odd...and i
- vi December 11, 2010N(N^2-1) == N(N+1)(N-1)
we need to show that there are atleast three 2's and and one 3 in this product so that it can be divisible by 24
if N is odd.. N+1 and N-1 are even...and even numbers are divisible by 2...so we have two 2's here...another 2 comes from the fact that two consecutive even numbers always have an extra 2 in their product...so this makes it three 2's
and any three consecutive numbers will be divisible by 3...