DWITE '10 R4 #2 - Primal Numbers

View as PDF

Submit solution

Points: 5
Time limit: 2.0s
Memory limit: 64M

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig
DWITE Online Computer Programming Contest, January 2011, Problem 2

Math sure likes their prime numbers, those with only two factors, 1 and itself. 2,3,5,7 are the first four prime numbers, written in a sequence (numbers following each other). We've made up a new sequence of numbers, primal numbers that are based on the values of the prime numbers sequence.

The 1st primal number is the value that is in the position #(value of the 1st prime) in the prime sequence. That is, the 1st prime is 2, and the prime number in 2nd position is 3, so the 1st primal number is 3.

The 2nd primal number is in position #(value of 2nd prime) in the prime sequence. 2nd prime is 3, and the 3rd prime is 5; so the 2nd primal number is 5. The sequence continues in the same pattern; 3, 5, 11, 17 are the first four primal numbers.

The input will contain 5 lines, integers 1 \le N \le 1000

The output will contain 5 lines, each the Nth primal number.

Note: think about performance for large values of N. The 1000th prime number is 7919, so you'd need the 7919th prime number to figure out what the 1000th primal number is.

Sample Input


Sample Output


Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0) Problem Resource: DWITE


There are no comments at the moment.