The solutions to this problem seem mostly similar, so I won't describe it separately.
First, run the Sieve of eratosthenes algorithm up to sqrt(B).
After that, loop from 1 to sqrt(B) and consider only the primes.
According to someone, you can roughly treat the number of primes from 1 to B as sqrt(B) when calculating.
In other words, the number of primes up to sqrt(B) is sqrt(sqrt(B)).
Now for each prime x,
keep multiplying by x while it's less than B.
In other words, for each prime you multiply logB times.
(By the properties of logarithms, the base of the log is omitted.)
Working out the time complexity, it's O(sqrt(B)*log(log(sqrt(B))) + sqrt(B) + sqrt(sqrt(B))*logB) =
O(sqrt(B)*log(log(sqrt(B))) + sqrt(sqrt(B))*logB).
Plugging in the worst case B = 10^14, it comes out under 200 million (time limit: 2 seconds), so
we can see it's solved in time.