We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent bb9dbfe commit 132e93dCopy full SHA for 132e93d
1 file changed
Sphenic Numbers/sphenic_numbers.py
@@ -0,0 +1,34 @@
1
+import math
2
+
3
+def primes(n):
4
+ sieve = [True] * n
5
+ for i in range(3, int(n**0.5) + 1, 2):
6
+ if sieve[i]:
7
+ for j in range(2*i, n, i):
8
+ sieve[j] = False
9
+ return [2] + [i for i in range(3, n, 2) if sieve[i]]
10
11
+def isSpehnic(num):
12
+ p = primes(num)
13
+ # The very smallest combiantion of primes would contain 2 and 3
14
+ # We only need to check numbers <= num/6
15
+ p = [n for n in p if n <= num//6]
16
+ l = len(p)
17
+ for i in range(l - 2):
18
+ for j in range(i+1, l-1):
19
+ for k in range(j+1, l):
20
+ if p[i] * p[j] * p[k] == num:
21
+ return True
22
+ return False
23
24
+def main():
25
+ n = int(input('Enter n: '))
26
+ count = -1
27
+ curr = 0
28
+ while count < n:
29
+ curr += 1
30
+ if isSpehnic(curr):
31
+ count += 1
32
+ print(curr)
33
34
+main()
0 commit comments