Skip to content

Commit fef9291

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 443836e commit fef9291

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

maths/next_prime_number.py

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

0 commit comments

Comments
 (0)