Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Ugly number
#python 3.6.9 def nextUgly(n): i2 = i3 = i5 = 0 next_ugly_number = 1 next_ugly = [None]*n next_ugly[0] = next_ugly_number next_multiple_of_2 = 2 next_multiple_of_3 = 3 next_multiple_of_5 = 5 for i in range(1,n): next_ugly_number = min(next_multiple_of_2,next_multiple_of_3,next_multiple_of_5) next_ugly[i] = next_ugly_number if(next_ugly_number == next_multiple_of_2): i2+=1 next_multiple_of_2 = next_ugly[i2]*2 if(next_ugly_number == next_multiple_of_3): i3+=1 next_multiple_of_3 = next_ugly[i3]*3 if(next_ugly_number == next_multiple_of_5): i5+=1 next_multiple_of_5 = next_ugly[i5]*5 return next_ugly[-1] n = int(input()) print(nextUgly(n))
run
|
edit
|
history
|
help
0
Contact Class
Python
Random integers
Faiha - L6
snake game counter
ReverseArray.py
PyRegFlags
Ej2_PYTHON_203700377.
Game4
Python3 complete func.