LC 1390 - Four Divisors
Approach Originally I thought that we just need to find the number that can be divided by two primes. num = prime1 * prime2, but got an WA, since I’ve ignored the num = prime1 * prime1 * prime1, such as 8 has 1, 2, 4, 8 as divisors. So the overall method is that we precalculate the prime and check the above conditions. My first submit is slow since I tried to build prime up to maxNum, but actually we can build to floor(sqrt(maxNum)). I was thinking that when prime1 is smaller in this square-root range, but prime2 would not, so I build the entire prime inside the whole range. Actually, even when prime2 is larger then the square-root range, we can walk the prime again and check if there are other divisors (this can reduce lots of complexity!). ...