How to check for division by 7 for big number in C++?

前端 未结 9 685
傲寒
傲寒 2020-12-17 01:57

I have to check, if given number is divisible by 7, which is usualy done just by doing something like n % 7 == 0, but the problem is, that given number can have

9条回答
  •  温柔的废话
    2020-12-17 02:30

    I'd start by subtracting some big number which is divisible by 7.

    Examples of numbers which are divisible by 7 include 700, 7000, 70000, 140000000, 42000000000, etc.

    In the particular example you gave, try subtracting 280000000000(some number of zeros)0000.

    Even easier to implement, repeatedly subtract the largest possible number like 70000000000(some number of zeros)0000.

提交回复
热议问题