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
3 Answers
+ 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.
0
will the program become efficient if i dont store the values of prime numbers i dont need but calculate it for all numbers
0
It will not become time efficient just with that, but it will improve in memory efficiency