forked from vedantpople4/problem_solving_cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlcmk.cpp
More file actions
39 lines (33 loc) · 638 Bytes
/
lcmk.cpp
File metadata and controls
39 lines (33 loc) · 638 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include<bits/stdc++.h>
using namespace std;
#define nl '\n'
#define ll long long
#define testcase long long t; cin>>t;
int gcd(int a, int b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
ll findlcm(ll arr[], ll n)
{
ll ans = arr[0];
for (int i = 1; i < n; i++)
ans = (((arr[i] * ans)) /
(gcd(arr[i], ans)));
return ans;
}
int main()
{
testcase;
while(t--){
ll n,m,k;
cin>>n>>m>>k;
ll a[n],b[n];
for(ll i=0;i<n;i++){
cin>>a[i];
b[i] = pow(a[i],k);}
cout<<findlcm(b,n)%m<<endl;
}
return 0;
}