Advertisement
Ahmed_Negm

new for charllenge

Apr 1st, 2023
707
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.57 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4. using namespace std;
  5. using namespace __gnu_pbds;
  6. #define ll long long
  7. #define OO 2'000'000'000
  8. #define ull unsigned long long
  9. #define nl '\n'
  10. #define sz(x) (ll)(x.size())
  11. #define all(x) x.begin(),x.end()
  12. #define rall(s)  s.rbegin(), s.rend()
  13. #define getline(s) getline(cin>>ws,s)
  14. #define ceill(n, m) (((n) / (m)) + ((n) % (m) ? 1 : 0))
  15. #define pi  3.141592653589793
  16. #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
  17. #define multi_ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
  18.  
  19.  
  20. void Fast_IO(){
  21. ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  22. // freopen("filename.in", "r", stdin);
  23. // freopen("filename.txt", "w", stdout);
  24. #ifndef ONLINE_JUDGE
  25. freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  26. #endif
  27. }
  28.  
  29.  
  30.  
  31.  
  32. int dx[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
  33. int dy[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
  34.  
  35.  
  36. ll phi(ll n) {
  37.     ll result = n;
  38.     for (ll i = 2; i * i <= n; i++) {
  39.         if (n % i == 0) {
  40.             while (n % i == 0)
  41.                 n /= i;
  42.             result -= result / i;
  43.         }
  44.     }
  45.     if (n > 1)
  46.         result -= result / n;
  47.     return result;
  48. }
  49.  
  50.  
  51. void solve(){
  52. ll x,y,m; cin>>x>>y>>m;
  53.  
  54. y = y%phi(m);
  55. ll ans = 1;
  56. while(y--){
  57.     ans = ans*x;
  58.     ans = ans%m;
  59. }
  60. cout<<ans<<nl;
  61.  
  62.  
  63.  
  64.  
  65.  
  66. }
  67.  
  68. int main(){
  69.     Fast_IO();
  70. int t =1;
  71. //cin>>t;
  72. while(t--){
  73. solve();
  74. }
  75. return 0;
  76. }  
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement