Skip to content

Instantly share code, notes, and snippets.

@sourcedelica
Last active September 24, 2015 03:10
Show Gist options
  • Save sourcedelica/e27d98fc7b6fc47d4c7e to your computer and use it in GitHub Desktop.
Save sourcedelica/e27d98fc7b6fc47d4c7e to your computer and use it in GitHub Desktop.
// https://www.hackerearth.com/submission/34845/
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set>
#include <vector>
#include <queue>
#include <map>
#include <iostream>
#include <cmath>
#define S(x) scanf("%d",&x)
#define P(x) printf("%d\n",x)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define pb push_back
using namespace std;
typedef long long int LL;
typedef vector<int > VI;
LL mod = 1000000007;
int prime[10000];
LL _pow(LL a,LL b) {
if(!b) return 1;
if(b == 1) return a;
if(b == 2) return (a*a)%mod;
if(b&1) return (a*_pow(a,b-1))%mod;
return _pow(_pow(a,b/2),2);
}
int main() {
int t;
S(t);
while(t--) {
int n;
long long int ans = 1;
memset(prime,0,sizeof(0)); // BUG - should be memset(prime,0,sizeof(0)*10000);
S(n);
while(n--) {
LL a;
scanf("%lld",&a);
for(LL i = 2; i*i <= a;i++) {
if(a%i == 0) {
int cnt = 0;
while(a%i == 0) {
a /= i;
cnt++;
}
prime[i] = max(cnt,prime[i]);
}
}
if(a>1) prime[a] = max(1,prime[a]);
}
rep(i,1,10000) ans = (ans*_pow(i,prime[i]))%mod;
printf("%lld\n",ans);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment