Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iomanip>
- #include <iostream>
- #include <functional>
- #include <algorithm>
- #include <math.h>
- #include <cmath>
- #include <string>
- #include <vector>
- #include<set>
- #include<map>
- #include <time.h>
- #include <fstream>
- using namespace std;
- typedef long long ll;
- typedef double ld;
- ll a, k, n;
- ll omar(ll p,ll N){
- if (N == 0)return 1;
- if (N == 1)return k;
- ll ans =omar(p, N / 2);
- if (N % 2 == 0)ans *= ans%p;
- else ans *= ans*k%p;
- return ans;
- }
- int main(){
- int ioi = 0;
- while (true)
- { ioi++; cin >> n >> k >> a;
- int t;
- if(n==0&&k==0&&a==0)return 0;
- cin >> t;
- ll p;
- for (int i = 0; i < t; i++){
- cin >> p;
- if (p == 0) break;
- else if (i == 0)cout << "Case " << ioi << ":" << endl;
- cout << a*omar( p,n)%p ;
- if(i<t-1)cout<<" ";
- } cout<<endl;
- //if(p!=0)cout<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement