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.
Instead of defining an array of primes, define an array of primorials to avoid calculating products. A Primorial is a product of the first n primes. Then simply perform an equality test in a loop and output the index of the array. Keep in mind that 16th primorial is larger than 2^64 so when defining your array, simply reduce the 16th primorial to fit into 2^64, but keep it larger than 10^18 limit specified by the question.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Leonardo's Prime Factors
You are viewing a single comment's thread. Return to all comments →
Instead of defining an array of primes, define an array of primorials to avoid calculating products. A Primorial is a product of the first n primes. Then simply perform an equality test in a loop and output the index of the array. Keep in mind that 16th primorial is larger than 2^64 so when defining your array, simply reduce the 16th primorial to fit into 2^64, but keep it larger than 10^18 limit specified by the question.