From 2d229759c3adc6f76d09a00f71e197967ff3b850 Mon Sep 17 00:00:00 2001 From: swamini-jadhav Date: Mon, 20 Oct 2025 16:09:40 +0530 Subject: [PATCH] Add Next_Prime_Number with prime checking logic Implement function to find the next prime number. --- maths/Next_Prime_Number.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 maths/Next_Prime_Number.py diff --git a/maths/Next_Prime_Number.py b/maths/Next_Prime_Number.py new file mode 100644 index 000000000000..03c0fc201e82 --- /dev/null +++ b/maths/Next_Prime_Number.py @@ -0,0 +1,24 @@ +""" +In the ancient city of Numeria, legends speak of an oracle whose whispers could bend the very fabric of mathematics. +Travelers from distant lands would bring her a number, and in return, she would reveal its future: the very next prime number. +Your task is to embody the oracle's wisdom. You will be given a number. +You must find the smallest prime number that is strictly greater than it. +""" +def check_prime(n): + if n<=1: + return False + if n<=3: + return True + if n%2==0 or n%3==0: + return False + temp=5 + while temp*temp<=n: + if n%temp==0 or n%(temp+2)==0: + return False + temp+=6 + return True +n=int(input()) +next_prime=n+1 +while not check_prime(next_prime): + next_prime+=1 +print(next_prime)