Testing divisibility by multiple numbers

后端 未结 5 1629
灰色年华
灰色年华 2021-01-13 03:46

In Python, is there a way to test if a number is divisible by multiple numbers without writing out the modulo operation for each factor?

More specifically, is there

5条回答
  •  一向
    一向 (楼主)
    2021-01-13 04:10

    (Note: This is of mathematical interest but the previous answers are better in practice.)

    You could compute the least common multiple of all the divisors and see if the number is divisible by that. (Just taking the product doesn't work; consider N=16 with divisors 4 and 8.)

提交回复
热议问题