How to make this Block of python code short and efficient

后端 未结 11 2508
天命终不由人
天命终不由人 2020-12-15 16:48

I am total newbie to programming and python. I was solving a problem. I found the solution but it seems like too slow.

    if n % 2 == 0 and n % 3 == 0 and\\         


        
11条回答
  •  清酒与你
    2020-12-15 17:19

    It's just a mathematical trick, use something like n % "LCM(1,2,...,20) == 0 which could be coded as:

    if n % 232792560 == 0:
        #do whatever you want
    

提交回复
热议问题