Pagini recente » Cod sursa (job #375735) | Cod sursa (job #352486) | Cod sursa (job #2780050) | Cod sursa (job #1497234) | Cod sursa (job #2685189)
#include <bits/stdc++.h>
//#pragma GCC optimize ("03")
#define FastIO ios_base::sync_with_stdio(false) , cin.tie(0) , cout.tie(0)
#define FILES freopen("inversmodular.in" , "r" , stdin) , freopen("inversmodular.out" , "w" , stdout)
#define ll long long
#define ull unsigned long long
#define ld long double
#define eb emplace_back
#define pb push_back
#define qwerty1 first
#define qwerty2 second
#define qwerty3 -> first
#define qwerty4 -> second
#define umap unordered_map
#define uset unordered_set
#define pii pair < int , int >
#define pq priority_queue
#define dbg(x) cerr << #x << ": " << x << '\n'
namespace FastRead
{
char buff[5000];int lg = 0 , p = 0;
char nc()
{
if(lg == p){lg = fread(buff , 1 , 5000 , stdin);p = 0;if(!lg) return EOF;}
return buff[p++];
}
template<class T>void read(T&x)
{
T sgn = 1; char c;while(!isdigit(c = nc()))if(c == '-')sgn = -1;
x = c - '0';while(isdigit(c = nc()))x = x * 10 + c - '0';x *= sgn;
}
}
using namespace FastRead;
using namespace std;
const int N = 1e5 + 10;
const int M = 1e9 + 7;
const ld PI = acos(-1);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll a , n;
ll pw(ll N , ll p)
{
ll ans = 1;
for( ; p ; p >>= 1 , N = N * N % n)
if(p & 1)
ans = ans * N % n;
return ans;
}
ll phi(ll n)
{
ll ans = 1 , d = 2;
while(d * d <= n)
{
ll pw = 1;
if(n % d == 0)
n /= d;
while(n % d == 0)
pw *= d , n /= d;
ans *= (d - 1) * pw;
++d;
}
if(n > 1)
ans *= n;
return ans;
}
signed main()
{
#ifndef ONLINE_JUDGE
FastIO , FILES;
#endif
cin >> a >> n;
cout << pw(a , phi(n) - 1);
return 0;
}