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
Francky:
2014-03-24 00:17:26
Problem fixed : I feel really stupid. For MasterJudge, you have to select an extension (.C++ for most masterjudge), if not you have silently 'internal error' for each submission. I saw this 'thing' but simply ignore it, as I thought all masterJudges were (.C++).
|
|
(Tjandra Satria Gunawan)(曾毅昆):
2014-03-24 00:05:20
Yes, I deleted my previous message, I think you haven't see it (deleted ~5 min after I post it).. I delete it because I know (very supicious) that there must be better complexity, so I change my mind, cancel my request, delete it.. but you very fast (Or I very slow) :-P and you've seen my comment before I deleted it :-O haha, nevermind ;-)
|
|
Francky:
2014-03-24 00:05:20
I don't want to spoil, but the awaited correct complexity here is different, it is although possible to solve it with 'conventional' method. Done in 222B of Py3 or 690B of C for me, without golfing. For now, only Min_25 solved the problem in the way it was designed for. I've set the time 'relax' to allow Python submissions, but time limit would have been much lower. In fact I would like this problem as a speed challenge ; maybe possible in near future. I don't think a tutorial edition is needed ; you have the excellent PRINT, possibly helpful for conventional method optimization, and really very hard in Py2.7 ;-) . I can think too at a more serious edition where only fast languages could be able to get AC in time, with the good method, without constant optis.
|
|
(Tjandra Satria Gunawan)(曾毅昆):
2014-03-24 00:05:20
Again, I'm not smart enough to enjoy your very good problem..
|
|
[Lakshman]:
2014-03-24 00:05:20
@Min_25 amazing speed .
|
|
Francky:
2014-03-24 00:05:20
Congratulations to Robert Gerbicz as the first solver.
|
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 |