Loading Now

findMaxCommonMultipleOfThreeNumbersInRange

Today, Jack went to house of one of his best friends – Jane. When he came to Jane’s home, Jane was crying in front of the front door. He run toward Jane and then asked her what had happended. Jane said that her most favourite toy had been stolen. And the theif had left a letter on the floor.

It was said that : “I’m the phantom theif, I just came through your house and then I saw your toy, it’s like the toy I used to play when I was a child, so, I decied to steal it. But I think that you must be very sad if you lose it, so, why don’t we play a game ? And if you win, I’ll give it back to you, but if you lose, it will be mine forever. Moahhahahaha.

This is the puzzle for you :
Do you know least common multiple of 2 numbers ? If not, maybe this will be useful (https://en.wikipedia.org/wiki/Least_common_multiple).

Now, I give you a number n and you have to choose 3 numbers in range [1,n] that the least common multiple of these numbers is maximum. Easy right ? You only have 24 hours to solve this. So let’s begin our game. Hahahahaahah”
Jack was very angry, but he is not good at math so he asked you to write a program to solve this and help Jane taking back her toy.
Given a number n, return the maximum least common multiple of 3 numbers in range [1,n].

Example: 

  • With input is n = 5. The output should be: findMaxCommonMultipleOfThreeNumbersInRange(n) = 60
    Because: 
    Least common multiple of 1 2 3 is: 6
    Least common multiple of 1 2 4 is: 4
    Least common multiple of 1 2 5 is: 10
    Least common multiple of 1 3 4 is: 12
    Least common multiple of 1 3 5 is: 15
    Least common multiple of 1 4 5 is: 20
    Least common multiple of 2 3 4 is: 12
    Least common multiple of 2 3 5 is: 30
    Least common multiple of 2 4 5 is: 20
    Least common multiple of 3 4 5 is: 60
    As you can see: maximum least common multiple of 3 numbers in range[1,5] is 60 with 3 numbers: 3,4,5

Input/Output:

  • [Execution time limit] 0.5s with C++, 3s with Java, C#, 4s with Python, Java Script

  • [Input] integer n

          1 ≤ n ≤ 10

  • [Output] int64

    The maximum least common multiple of 3 numbers in range [1,n]
    The answer is in range [1, 263 - 1]

Post Comment

Contact