有一堆棋子,2枚2枚的数,最后余1枚;3枚3枚的数,最后余2枚;5枚5枚的数,最后余4枚;6枚6枚的数,最后余5枚;7枚7枚的数,正好数完。这堆棋子最少有多少棋子。...

分析

  • 最小公倍数=两整数的乘积÷最大公约数
  • 2枚2枚的数,最后余1枚,故该棋子是奇数。
  • 棋子个数+1是2,、3、5、6的公倍数,故为5、6的公倍数。
  • 5、6的最小公倍数是30。
  • 棋子个数是7的公倍数。
    综上所知,棋子数n+1是30的公倍数,n是7的公倍数
function test()
{
    $count = 0;
    $i = 0;
    do{
        $i++;
        $b = $i*30-1;
        if ($b%7 == 0) {
            $count = $b;
        }
    }while (!$count);
    return $count;
}

猜你喜欢

转载自blog.csdn.net/weixin_34235457/article/details/86992457