Advertisement
jeff69

Untitled

Mar 24th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. #include <iomanip>
  2. #include <iostream>
  3. #include <functional>
  4. #include <algorithm>
  5. #include <math.h>
  6. #include <cmath>
  7. #include <string>
  8. #include <vector>
  9. #include<set>
  10. #include<map>
  11. #include <time.h>
  12. #include <fstream>
  13. using namespace std;
  14. typedef long long ll;
  15.  
  16. typedef double ld;
  17. ll a, k, n;
  18. ll omar(ll p,ll N){
  19. if (N == 0)return 1;
  20. if (N == 1)return k;
  21. ll ans =omar(p, N / 2);
  22. if (N % 2 == 0)ans *= ans%p;
  23. else ans *= ans*k%p;
  24. return ans;
  25. }
  26. int main(){
  27.  
  28. int ioi = 0;
  29. while (true)
  30.  
  31.  
  32. { ioi++; cin >> n >> k >> a;
  33. int t;
  34. if(n==0&&k==0&&a==0)return 0;
  35. cin >> t;
  36.  
  37. ll p;
  38.  
  39. for (int i = 0; i < t; i++){
  40. cin >> p;
  41.  
  42. if (p == 0) break;
  43. else if (i == 0)cout << "Case " << ioi << ":" << endl;
  44. cout << a*omar( p,n)%p ;
  45. if(i<t-1)cout<<" ";
  46.  
  47.  
  48.  
  49.  
  50. } cout<<endl;
  51. //if(p!=0)cout<<endl;
  52.  
  53.  
  54.  
  55. }
  56.  
  57.  
  58.  
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement