SUMPRIM1 - Sum of primes
Léo had been defeated by XerK at the battle of the ThermoPell. 300 braves fell ; XerK as a living God decided to allow a new honor table, for those who can use less than 900 characters in his new problem. This problem is extremely simple, but you have to be extremely fast.
Input
The lonely line of input contains an integer N.
Output
You have to print the sum of all primes up to N.
Examples
Input_1: 19
Output_1: 77
Input_2: 1000000000
Output_2: 24739512092254535
Explanation
The first sum is
2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 = 77
Constraints
0 < N <= 2×10^9
The classical problem SUMPRIM2 is the reverse task. Time limit allows some slow languages to finish in time, it could be hard. For your information, my 690-Byte C code need a total time of 0.76s for the 30 input files, 22.82s for my Python one. (Edit 12/II/2017, after compiler update). Warning : You have 900B as code size limit. ;-) Have fun.
hide comments
veteran_01:
2021-02-11 08:52:47
we cannot use python here
|
|
mahmud2690:
2018-05-04 10:15:40
Learned how to make code pretty ugly due to source limit)
|
|
aliosm:
2018-04-29 10:43:15
Any hint in how to start to solve this problem?
|
|
dp_v1:
2016-04-15 15:10:22
@Francky,
|
|
weathervane:
2015-08-15 19:04:04
I am confused by the question's requirements. It states there will be one input case, but the author talks about 30 input cases. It also gives a time limit of 2.0 seconds, yet answers have been accepted with much larger time than that. Correct answers are awarded a score. Where is that mentioned in the question?
|
|
sivanatarajan:
2014-10-17 17:57:29
I got time limit exceeded in 30th test case :-(
|
|
mehmetin:
2014-07-21 10:18:11
Simple segmented sieve takes ~9 seconds to run for 2x10^9, on my machine... Last edit: 2014-07-21 10:24:50 |
|
Francky:
2014-06-10 11:22:51
Congratulations to Min_25 as the first solver with a slow language, and as solver in the way the problem was designed for. |
|
Viplov Jain:
2014-06-02 12:53:55
@francky why put a size limit?
|
|
[Lakshman]:
2014-05-03 20:11:09
@francky am I getting WA for 2*10^9?
|
Added by: | Francky |
Date: | 2014-03-09 |
Time limit: | 2s |
Source limit: | 900B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 |
Resource: | Own Problem |