primepie

Problem Description

Bradley is eating an entire series of pies for lunch. However, since Bradley is an epic math geek, these pies are not just normal pies, they are PRIME PIES. Prime pies have a very special property. Their weights are always prime. Thus, there will be a prime pie of 2kg, 3kg, 5kg, but not 4kg. The prime pies are also always sorted in order. So the first prime pie will be one with 2kg, the second one will be 3kg, the third one will be 5kg, etc.

Bradley wants to eat N prime pies for lunch today. He will always start eating the prime pies from the smallest one first. So, in a case where N = 4, Bradley will eat the 2kg pie, then the 3kg pie, then the 5kg pie and then the 7kg pie. Thus, Bradley would have eaten a total of 2+3+5+7=17 kg of prime pies. Given N, help Bradley find out the total amount of prime pies he would have eaten in kg.

Your program should implement the following functions:

  1. long long int amountEaten(int N), which should return the total amount of prime pies Bradley would have eaten.

Limits

Subtask 1 (9%): 1 <= N <= 100
Subtask 2 (12%): 1 <= N <= 1 000
Subtask 3 (27%): 1 <= N <= 10 000
Subtask 4 (52%): 1 <= N <= 1 000 000
It is also guranteed that the millionth prime is less than 20 000 000.

Sample Input 1

4

Sample Output 1

17


Submitting .cpp to 'primepie'


You're not logged in! Click here to login

Time Limit: 1.5 Seconds
Memory Limit: 256MB
Your best score: 0
Source: Dunjudge Archive

Subtask Score
1 9
2 12
3 27
4 52
5 0