Calculate LCM of N numbers modulo 1000000007

后端 未结 4 1568
没有蜡笔的小新
没有蜡笔的小新 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

    your approach is wrong as mentioned by johnchen902.

    Here is my approach:

    for i=1 to n
        a.take i_th number as x
        b.reduce(devide) remaining numbers(i+1_th to n_th) by their gcd with x
        c.multiply x to ans and take mod of ans
    return ans
    

    SEE AT IDEONE

提交回复
热议问题