접근 1 :
1. Calculate all prime numbers in the given range (2,R) using
sieve of eratosthenes.
2. Initialize the result as number of primes(say NP) since all primes
are having prime number(2) of divisors.
3. For each prime((P), we can generate maximum of NP - 1 numbers
that has prime number of divisors.
Let say P1,P2,P3,....Pn are prime numbers of range (L,R).
NP is the number of primes of range (L,R).
Each prime has 2(prime number of) divisors.
Square(3 - 1) of prime has 3 divisors.
4th power(5 - 1) of prime has 5 divisors.
...
nth power(n + 1 (is prime) - 1) of prime has n+1 divisors.
Increment the result by 1 if pow(Pi, Pj -1) <= R, i >= L, j<=R and i != j
Note : All primes in an array(AP) are increasing numbers(sorted), so we can
also use the modified binary search to find the numbers of
prime divisors in a given range
접근 2 : (내 동료에 의해 제안 나 개선)
1. Create a divisors array that can hold R - L - 1 number of elements and
initialize it to zero.
2. Iterate i from L to R
3. Check if divisors(i) <> 0. Go to step 2 if divisors(i) = 0.
4. compute the absolute difference of number of divisors of i and i * p (prime).
5. The absolute difference between the number of divisors of i, i * p and
i*p, i*p*p are same.
a = number of divisor of i
d = difference of number of divisors of i * 2 and i.
divisors(i-L) = a
p = 2(prime number)
n = distance from a in arithemetic progression
iterate j from i * p to R, j = j * p
divisors(j-L) = a + n * d
n = n + 1
6) Filter divisors array to find prime number of divisors
당신이 뭘하려하는 코드를 게시 할 수 있습니까? – damienfrancois
네 물론 .... 링크 : http://ideone.com/u9zd0o –
하지만 그것은 최대 1,000,000까지 작동합니다. 최대 1,000000000000 번까지 필요합니다. –