Update all new Tasks
This commit is contained in:
parent
00a190b0a6
commit
91df62d461
5697 changed files with 93386 additions and 804 deletions
19
Task/Almost-prime/Python/almost-prime.py
Normal file
19
Task/Almost-prime/Python/almost-prime.py
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
from prime_decomposition import decompose
|
||||
from itertools import islice, count
|
||||
try:
|
||||
from functools import reduce
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
def almostprime(n, k=2):
|
||||
d = decompose(n)
|
||||
try:
|
||||
terms = [next(d) for i in range(k)]
|
||||
return reduce(int.__mul__, terms, 1) == n
|
||||
except:
|
||||
return False
|
||||
|
||||
if __name__ == '__main__':
|
||||
for k in range(1,6):
|
||||
print('%i: %r' % (k, list(islice((n for n in count() if almostprime(n, k)), 10))))
|
||||
Loading…
Add table
Add a link
Reference in a new issue