fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4. typedef unsigned long long ull;
  5. const ull mod=1000000007;
  6. ull A[10009];
  7. /*Euclidean GCD*/
  8. ull gcd(ull a,ull b)
  9. {
  10. while( b != 0)
  11. {
  12. ull t = b;
  13. b= a %t;
  14. a = t;
  15. }
  16. return a;
  17. }
  18. ull lcm(ull a, ull b)
  19. {
  20. return (a/gcd(a,b))%mod*(b%mod);
  21. }
  22. ull lcms(int l ,ull * A)
  23. {
  24. int i;
  25. ull result;
  26. result = 1;
  27. for (i = 0; i < l; i++)
  28. result = lcm(result, A[i])%1000000007;
  29. return result;
  30. }
  31. int main()
  32. {
  33. int T;
  34. cin>>T;
  35. while(T--)/*Number of test cases*/
  36. {
  37. int N;
  38. cin>>N;/*How many Numbers in Array*/
  39. for(int i=0;i<N;++i)
  40. {
  41. cin>>A[i];//Input Array
  42. }
  43. cout<<lcms(N,A)%1000000007<<endl;
  44. }
  45. return 0;
  46. }
Success #stdin #stdout 0s 2980KB
stdin
2
4
2 4 6 8
3
2 3 1
stdout
24
6