Advertisement
Guest User

Untitled

a guest
May 22nd, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int lim = 99999999;
  4. const int MOD = 1e9 + 7;
  5. long long POW(int x , int y){
  6.     if(y == 0) return 1;
  7.     long long ret = POW(x , y/2);
  8.     ret *= ret; ret %= MOD;
  9.     if(y % 2) ret *= x , ret %= MOD;
  10.     return ret;
  11. }
  12. map < int , int > facts;
  13. int main(){
  14.     int n;
  15.     scanf("%d",&n);
  16.     for(int j = 1 ; j <= n ; j++){
  17.         int x;
  18.         scanf("%d",&x);
  19.         for(int i = 2 ; i * i <= x ; i++){
  20.             while(x % i == 0){
  21.                 facts[i]++;
  22.                 x /= i;
  23.             }
  24.         }
  25.         if(x > 1) facts[x]++;
  26.     }
  27.     long long ret = 1;
  28.     bool ok = 1;
  29.     for(auto pp : facts){
  30.         if(pp.second % n == 0){
  31.             pp.second /= n;
  32.             for(int j = 0 ; j < pp.second ; j++)
  33.                 ret *= pp.first;
  34.         }
  35.         else ok = 0;
  36.     }
  37.     if(ok){
  38.         puts("justdoit");
  39.     //    cout<<ret<<endl;
  40.     }
  41.     else {
  42.       //  puts("3tees");
  43.         ret = 1;
  44.         for(auto pp : facts){
  45.             pp.second %= (n + 1);
  46.             int aa = n + 1 - pp.second;
  47.             aa %= (n + 1);
  48.             ret *= POW(pp.first , aa);
  49.             ret %= MOD;
  50.         }
  51.         cout<<ret<<endl;
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement