We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
def multiple(number):
return (
helper(3,number) +helper(5,number)-helper(15,number)
) this function has passed all the test cases as it eliminates the use of traditional for loops and use of mathematical expressions
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #1: Multiples of 3 and 5
You are viewing a single comment's thread. Return to all comments →
def helper(n,k): p=(k-1)//n return n*p*(p+1)//2
def multiple(number): return ( helper(3,number) +helper(5,number)-helper(15,number) ) this function has passed all the test cases as it eliminates the use of traditional for loops and use of mathematical expressions