Charlie and Prime Numbers
All submissions for this problem are available.
Charlie has a fascination for Prime Numbers. But he never went to school so he always makes a mistake when he is asked to tell whether a number is a Prime Number or not. So, he asks his brother Alan to help him out with this. Your job is to help Alan in writing a program which prints THE SUM of all prime numbers between M and N (inclusive).
The first Line of Input will contain an Integer T , Denoting the number of Test Cases.
The next T Lines, each, will have 2 space separated Integers M and N
For Each Test Case, Output a single Line containing the SUM of all Prime Numbers between M and N (inclusive).It would be advisable to use Long Datatype for storing the sum.
- Subtask 1: (30 Points): M <=10^3, N<=10^3
- Subtask 2: (70 Points): M<=5*10^6, N<=5*10^6
In the first case, Prime Numbers between 1 and 8 are 2, 3, 5 and 7. Their sum is 17.
In the second case, Prime Numbers between 37 and 45 are 37, 41 and 43. Their sum is 121.
Note: The Input and Output Format must be strictly followed. Each output MUST be on a new LINE. JAVA users must be careful while using BufferedReader for Input Format as Two Integers cannot be Inputted on the same line while using BufferedReader. Any mistake in the input format might make a correct solution give a Wrong Answer while submitting.
|Tags||animesh_f, cdqu2014, prime, sieve, simple|
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, PYP3, CLOJ, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.