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.

For last 5 test case, common method,to iterate from 1 to sqrt(n) to fetch all divisors, would fail with time out. Thus, we need an efficient way to find all divisors. Here's my method, hope this helps.

calculate all primes less than sqrt(8000000) +1

find all prime divisors and how many times each prime divisor shows up for n.

With the result in step 2, we can find all divisors less than sqrt(n) + 1 for n,

Iterate divisors we got from step 3, calculate how many solutions for n.

Cookie support is required to access HackerRank

Seems like cookies are disabled on this browser, please enable them to open this website

## Project Euler #135: Same differences

You are viewing a single comment's thread. Return to all comments →

For last 5 test case, common method,to iterate from 1 to sqrt(n) to fetch all divisors, would fail with time out. Thus, we need an efficient way to find all divisors. Here's my method, hope this helps.

sqrt(8000000) +1n.sqrt(n) + 1forn,n.