Calculate LCM of N numbers modulo 1000000007

后端 未结 4 1575
没有蜡笔的小新
没有蜡笔的小新 2020-12-22 03:32

I was solving following problem on LCM : Calculate LCM of N numbers modulo 1000000007

My approach :

typedef unsigned long long ull;
         


        
4条回答
  •  悲哀的现实
    2020-12-22 03:47

    1000000007 is too big for me to take as an example. Let me use 17 for example:

    LCMS(10, 9, 8) % 17 =
    LCM(10, LCM(9, 8)) % 17 =
    LCM(10, 72) % 17 =
    360 % 17 =
    3
    

    This is what your code doing:

    LCMS(10, 9, 8) % 17 =
    LCM(10, LCM(9, 8) % 17) % 17 =
    LCM(10, 72 % 17) % 17 =
    LCM(10, 4) % 17 =
    40 % 17 =
    6
    

    Which is wrong.

    ALSO AT IDEONE

提交回复
热议问题