Skip to content

Commit 2d22975

Browse files
Add Next_Prime_Number with prime checking logic
Implement function to find the next prime number.
1 parent e2a78d4 commit 2d22975

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

maths/Next_Prime_Number.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""
2+
In the ancient city of Numeria, legends speak of an oracle whose whispers could bend the very fabric of mathematics.
3+
Travelers from distant lands would bring her a number, and in return, she would reveal its future: the very next prime number.
4+
Your task is to embody the oracle's wisdom. You will be given a number.
5+
You must find the smallest prime number that is strictly greater than it.
6+
"""
7+
def check_prime(n):
8+
if n<=1:
9+
return False
10+
if n<=3:
11+
return True
12+
if n%2==0 or n%3==0:
13+
return False
14+
temp=5
15+
while temp*temp<=n:
16+
if n%temp==0 or n%(temp+2)==0:
17+
return False
18+
temp+=6
19+
return True
20+
n=int(input())
21+
next_prime=n+1
22+
while not check_prime(next_prime):
23+
next_prime+=1
24+
print(next_prime)

0 commit comments

Comments
 (0)