Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- //#pragma GCC optimize("Ofast")
- //#pragma GCC target("avx,avx2,fma")
- //#pragma GCC optimization ("unroll-loops")
- #define int long long
- #define pb push_back
- #define all(s) s.begin(),s.end()
- #define pii pair<int,int>
- #define fr first
- #define sc second
- #define bst ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
- #define endl "\n"
- using namespace std;
- const int N = 1e5 + 10, mod = 1e9 + 7, inf = 1e18 + 7;
- const double pi = acos(-1);
- int lp[2 * N+1];
- vector<int> pr;
- void solve() {
- //soln
- int n;
- cin >> n;
- int a[n];
- for(int i = 0; i < n; i++) {
- cin >> a[i];
- }
- if(n == 1) {
- cout << a[0] << endl;
- return;
- }
- int ans = 1;
- for(int i = 0; pr[i] * pr[i] <= N; i++) {
- map<int, int> mp;
- for(int j = 0; j < n; j++ ){
- int pw = 0, tmp = a[j];
- while(tmp % pr[i] == 0) {
- tmp /= pr[i];
- pw++;
- }
- if(mp.count(pw) == 0) {
- mp.insert({pw, 1});
- } else {
- mp[pw]++;
- }
- }
- for(auto it: mp) {
- if(it.second >= 2) {
- ans *= pow(pr[i], it.first);
- break;
- }
- }
- }
- cout << ans << endl;
- }
- main() {
- bst;
- for (int i=2; i<=N; ++i) {
- if (lp[i] == 0) {
- lp[i] = i;
- pr.push_back (i);
- }
- for (int j=0; j<(int)pr.size() && pr[j]<=lp[i] && i*pr[j]<=N; ++j)
- lp[i * pr[j]] = pr[j];
- }
- int t = 1;
- //cin >> t;
- while(t--) {
- solve();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement