First of all we need to find all the prime numbers up to 1000000. After we found and stored all the prime numbers we need to keep an answer array SUM where SUM[i] will show the sum of all the prime numbers with index 1 to i. After this we read the number N , find the prime number which doesn't exceed N and output value SUM[index] where index is the index of the greatest prime not bigger than N.
No comments:
Post a Comment