Oblicz LCM N liczb modulo 1000000007

Rozwiązywałem następujący problem na LCM:Oblicz LCM N liczb modulo 1000000007

Moje podejście:

typedef unsigned long long ull;
const ull mod=1000000007;
ull A[10009];
/*Euclidean GCD*/
ull gcd(ull a,ull b)
{
    while( b != 0)
    {
        ull  t = b;
        b= a %t;
        a = t;
    }
    return a;
}
ull lcm(ull a, ull b) 
{ 
    return (a/gcd(a,b))%mod*(b%mod); 
}
ull lcms(int  l ,ull * A)
{
    int     i;
    ull result;
    result = 1;
    for (i = 0; i < l; i++) 
        result = lcm(result, A[i])%1000000007;
    return result;
}
int main()
{
    int T;
    cin>>T;
    while(T--)/*Number of test cases*/
    {
        int N;
        cin>>N;/*How many Numbers in Array*/
        for(int i=0;i<N;++i)
        {
            cin>>A[i];//Input Array
        }
        cout<<lcms(N,A)%1000000007<<endl;
    }
    return 0;
}

Otrzymuję Zły Odpowiedź, gdy przesyłam moje rozwiązanie. Ograniczenia to:

1<=N<=1000
and 1<=A[i]<=10000

AT IDEONE

Myślę, że otrzymuję Wrong Answer z powodu przepełnienia. Jak mogę poprawić swój kod?

Dzięki!

questionAnswers(3)

yourAnswerToTheQuestion