Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define int long long
- #define inf 2e18
- using namespace std;
- int MOD=1000000007;//998244353 //change as per requirement
- void FASTIO(){ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
- int power(int a,int b)
- {
- int val=1;
- while(b>0)
- {
- if(b&1)
- val=((val*a)%1337);
- a=((a*a)%1337);
- b>>=1;
- }
- val%=1337;
- return val;
- }
- int solve(int a,vector<int> b)
- {
- int m=1337,ans=1,val1,val2;
- a=(a%m);
- for(int i=0;i<b.size();i++)
- {
- val1=((b[i]*power(10,(b.size()-i-1)))%m);
- val2=((power(a,val1))%m);
- ans=((ans*val2)%m);
- ans%=m;
- }
- return ans;
- }
- main()
- {
- auto start=chrono::system_clock::now();
- {
- #ifndef ONLINE_JUDGE
- freopen("input.txt","r",stdin);
- freopen("output.txt","w",stdout);
- #endif
- FASTIO();
- int t=1;
- cin>>t;
- while(t--)
- {
- int a,n,x; cin>>a>>n;
- vector<int> b;
- for(int i=0;i<n;i++)
- {
- cin>>x;
- b.push_back(x);
- }
- cout<<solve(a,b);
- }
- }
- auto end=chrono::system_clock::now();
- chrono::duration<double> elapsed=end-start;
- // cout<<" Time taken: "<<elapsed.count()<<"sec";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement