Skip to content

FizzBuzz with 4 and 6 · ⁨4 和 6 的 FizzBuzz⁩

English

FizzBuzz with 4 and 6

A FizzBuzz with a trap in it.

Test for both first, with n % 4 == 0 and n % 6 == 0. Multiplying the two numbers, n % 24 == 0, looks like a shortcut but misses 12: a number can divide by 4 and by 6 without dividing by 24.

中文

4 和 6 的 FizzBuzz

一个藏着陷阱的 FizzBuzz。

要先判断两者都是:n % 4 == 0 and n % 6 == 0。把两个数相乘写成 n % 24 == 0 看起来像捷径,却会漏掉 12:一个数可以同时被 4 和 6 整除,却不能被 24 整除。

Log in or create account · ⁨登录或创建账户⁩

IGCSE, A-Level · ⁨IGCSE、A-Level⁩ & AP · ⁨与 AP⁩