SUMPRIM2 - Sum of primes (reverse mode)
XerK had prepared his new problem with some sums of primes up to some bounds. His results are well here, but he forgot the bounds. Your task is to find which was the last prime in the sum. This problem is extremely simple, but you have to be extremely fast.
The lonely line of input contains an integer S.
You have to print the last prime P such that sum(prime from 2 to P) = S.
The first sum was
2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 = 77
0 < P <= 10^12
The challenge problem SUMPRIM1 is the reverse task. Time limit is set to allow some slow languages to finish in time, it could be hard. For your information, there's a total of 20 input files. ;-) Have fun.
@Francky what is the expected complexity is it $O(\ sqrt(P) \ log P)$
What's the limit on S. WIll it fit in long long ?
@ francky-Is the value of s always prime?