0

How do i print prime number at given k'th position without checking for all numbers occurring before kth number

i started by making an array which stores prime number and has a size of k. then i printed tge last term. This method works for smaller values of k but is slow and inefficient for bigger values of k please suggest an algorithm which directly gives kth element without wasting time on rest numbers

24th Feb 2018, 7:18 PM
Aayush Singh
Aayush Singh - avatar
3 Respostas
+ 1
Prime numbers cannot be directly calculated, or at least we dont know of a way yet. To calculate the nth prime number you would need to calculate all previous ones. This is why there are rewards for calculating new prime numbers (around 200 000 $ per number i think). To make this fast you could store the already known numbers locally in a file and read it.
24th Feb 2018, 7:26 PM
spcan
spcan - avatar
0
will the program become efficient if i dont store the values of prime numbers i dont need but calculate it for all numbers
24th Feb 2018, 7:28 PM
Aayush Singh
Aayush Singh - avatar
0
It will not become time efficient just with that, but it will improve in memory efficiency
26th Feb 2018, 6:06 AM
spcan
spcan - avatar