fork(24) download
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4. typedef unsigned long long ull;
  5. const ull mod=17;
  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])%17;
  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)%17<<endl;
  44. }
  45. return 0;
  46. }
Success #stdin #stdout 0s 2936KB
stdin
1
3
10 9 8
stdout
6