diff options
Diffstat (limited to 'progs/dont_care/a242.py')
-rw-r--r-- | progs/dont_care/a242.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/progs/dont_care/a242.py b/progs/dont_care/a242.py new file mode 100644 index 0000000..dc0ceec --- /dev/null +++ b/progs/dont_care/a242.py @@ -0,0 +1,12 @@ +import heapq
+def nth_super_ugly_number(n, primes):
+ uglies = [1]
+ def gen(prime):
+ for ugly in uglies:
+ yield ugly * prime
+ merged = heapq.merge(*map(gen, primes))
+ while len(uglies) < n:
+ ugly = next(merged)
+ if ugly != uglies[-1]:
+ uglies.append(ugly)
+ return uglies[-1]
\ No newline at end of file |