Advertisement
fireLUFFY

SuperPow

May 20th, 2021
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.19 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. #define int long long
  4. #define inf 2e18
  5. using namespace std;
  6.  
  7. int MOD=1000000007;//998244353          //change as per requirement
  8. void FASTIO(){ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
  9.  
  10. int power(int a,int b)
  11. {
  12.     int val=1;
  13.     while(b>0)
  14.     {
  15.         if(b&1)
  16.             val=((val*a)%1337);
  17.         a=((a*a)%1337);
  18.         b>>=1;
  19.     }
  20.     val%=1337;
  21.     return val;
  22. }
  23. int solve(int a,vector<int> b)
  24. {
  25.     int m=1337,ans=1,val1,val2;
  26.     a=(a%m);
  27.    
  28.     for(int i=0;i<b.size();i++)
  29.     {
  30.         val1=((b[i]*power(10,(b.size()-i-1)))%m);
  31.         val2=((power(a,val1))%m);
  32.         ans=((ans*val2)%m);
  33.         ans%=m;
  34.     }
  35.     return ans;
  36. }
  37. main()
  38. {
  39.     auto start=chrono::system_clock::now();
  40.     {
  41.         #ifndef ONLINE_JUDGE
  42.             freopen("input.txt","r",stdin);
  43.             freopen("output.txt","w",stdout);
  44.         #endif
  45.         FASTIO();  
  46.         int t=1;
  47.         cin>>t;
  48.         while(t--)
  49.         {
  50.             int a,n,x;  cin>>a>>n;
  51.             vector<int> b;
  52.             for(int i=0;i<n;i++)
  53.             {
  54.                 cin>>x;
  55.                 b.push_back(x);
  56.             }
  57.             cout<<solve(a,b);
  58.         }
  59.     }
  60.     auto end=chrono::system_clock::now();
  61.     chrono::duration<double> elapsed=end-start;
  62. //  cout<<" Time taken: "<<elapsed.count()<<"sec";
  63.     return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement