All Tracks Math Number Theory Primality Tests Problem

Ryotsu loves Primes
Tag(s):

Basic Programming, Easy, Math, Sieve

Problem
Editorial
Analytics

Ryotsu loves playing with prime numbers. His father was a mathematics professor. To test Ryotsu's knowledge of primes, his father gave him a simple task. The task is to find the sum of every Kth prime numbers in given list of numbers. He's having trouble solving it, being an elementary school student. Help him accomplish the task.

Input Format:
The first line of the input contains an integer T denoting the number of test cases.
Each test case contains two space separated integers N and K followed by N space separated numbers.

Output Format:
For each test case, output the sum of every Kth prime number followed by newline.

Constraints:

  • 1 ≤ T ≤ 10000
  • 1 ≤ N ≤ 106
  • 1 ≤ K ≤ 100
  • 0 ≤ Ai ≤ 106
SAMPLE INPUT
2
11 3
1 2 3 4 5 6 7 8 3 11 6
7 2
1 2 13 3 5 6 7
SAMPLE OUTPUT
16
18
Explanation

In Case 1, N=11 and K=3. First occurrence of Kth prime number is 5. Second occurrence of Kth prime number is 11 so sum is 16.
Similarly for Case 2, sum is 18.

Time Limit: 0.5 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Julia, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Swift, Visual Basic, Kotlin

CODE EDITOR

Initializing Code Editor...
Your Rating:

Contributor

This Problem was Asked in

SKIT, Jaipur

Challenge Name

Code Emblaze

OTHER PROBLEMS OF THIS CHALLENGE
Notifications
View All Notifications