-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathTheConfusedMonk.cpp
More file actions
52 lines (46 loc) · 886 Bytes
/
TheConfusedMonk.cpp
File metadata and controls
52 lines (46 loc) · 886 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
40
41
42
43
44
45
46
47
48
49
50
51
52
#include<iostream>
#include<bits/stdc++.h>
#define q 1000000007
using namespace std;
int gcd(int a,int p)
{
if(a%p==0)
return p;
return gcd(p,a%p);
}
int calc(int a,int p)
{ long long int ans;
if(p==0)
return 1;
if(p==1)
return a;
ans=((calc(a,p/2)%q)*(calc(a,p/2)%q))%q;
if(p%2==1)
ans=(ans*a)%q;
return ans;
}
int main()
{
int n,i;
cin>>n;
int a[n];
for(i=0;i<n;i++)
cin>>a[i];
int p=a[0];
if(n==1);
else
{
for(i=1;i<n;i++)
{
p=gcd(a[i],p);
}
}
//cout<<"hcf"<<p<<"\n";
long long int prod=1;
int ans=1;
for(i=0;i<n;i++)
{ ans=calc(a[i],p);
prod=((prod%q)*(ans%q))%q;
}
cout<<prod;
}