Hint 1 Project Euler Problem 521 Smallest prime factor


Smallest prime factor

Problem 521

Let smpf(n) be the smallest prime factor of n.
smpf(91)=7 because 91=7×13 and smpf(45)=3 because 45=3×3×5.
Let S(n) be the sum of smpf(i) for 2 ≤ i ≤ n.
E.g. S(100)=1257.

Find S(1012) mod 109.

First thing comes into mind is Sieve of Eratosthenes. 
However, 10^12 equals to 1000G which would cost too much time/space in a average laptop. 

1, One thing comes into my mind is that obviously, Prime > 10^6 is only going to be count once.
Therefore, take the S(100) as an example;

S(100)= 2*50 + 3*17 + 5*7 + 7*4 + sum(prime < 100) - sum(prime < 10)
(Note: sum(prime < N) is calculable in wolfram alpha, we don't have to worry about that part at least.)

2, Now let us take a look at the smallest primes.
//Define sum_p(P) = count_p(P)*P;
//Define count_p(P) = count of smpf(i)=P;

We don't need to worry about prime(1) = 2.
Because there will always be sum_p(2) = (10^12 / 2) * 2 = 10^12;
It turns out to be 0 when mod 10^9. 
sum_p(2) mod 10^9 = 0;

As for prime(2) = 3, sum_p(3) = upper{(10^12-1)/3/2} * 3 = 5*10^11+1;
sum_p(3) mod 10^9 = 1;

3, Now we will have to deal with 3<prime<10^6 which is 78496 primes.
Let me think about this tonight and write more if I think of something.


---------------------
The opinion above is original and unproven work. Please correct me if I made a mistake.

Comments

  1. I don´t think there is any easy way to calculate the sum of the primes up to 10^12, but we know that the sum of the all numbers from 2 to 10^12 is 10^24-4. So we can take that number and for each non-prime x we subtract x and add smpf(x). We cannot do this separately for each non-prime (it would take too long), we need to calculate the sum of a series and use that. e.g multiples of 2, then multiples of 3 (excluding multiples of 2) etc.

    ReplyDelete

Post a Comment

Popular posts from this blog

Project Euler Problem 684 Inverse Digit Sum - Solution

Project Euler Problem 686 Powers of Two - Solution

Project Euler Problem 717 Summation of a Modular Formula - Solution