Monday, December 28, 2009

Given n-th prime, find (n+1)-th prime!

Problem: Given n-th prime, how do you find (n+1)-th prime? Write a function
int GetNextPrime(int n);
Example: 
Input: 7 Output: 11
Input: 13 Output: 17
Hint: Search for Bertrand's Postulate!

2 comments:

Unknown said...

Where r u from man !!! ... You seriously are sooooooooo intelligent ...... i wud really like to see all the code and algo that you have written on your own and that is soooooo optimum .....

Can you please show me the code to the prob mentioned here ?

Rajendra Kumar Uppal said...

@ tekpiks
Thanks for the reply and encouragement. However, I didn't designed any algorithm on myself. Considering the problem mentioned in this post, I just found out a mathematical concept of distance between prime numbers (see Bertrand's Postulate). I can show you all the code and algorithmic steps, but it's better for you if you first try to explore things on behalf of hints given here and try to code yourself!
Keep visiting.