#include <bits/stdc++.h>
#pragma GCC optimize(3)
using namespace std;
int aa,b,mod;
long long qpow(int a,int dep)
{
   if(dep==1) return a;
   long long k=qpow(a,dep/2);
   if(!dep%2) return k*k%mod;
   return qpow(a,dep-1)*a%mod;
}
int main()
{
   std::ios::sync_with_stdio(false);
 std::cin.tie(0);
    cin>>aa>>b>>mod;
    if(b==0) cout<<1%mod,exit(0);
    if(aa==0) cout<<0,exit(0);
    cout<<qpow(aa,b)%mod;
	return 0;
}

3 comments

  • @ 2022-12-21 20:30:54

    是否有可能多次访问到同一个 depdep 然后做了大量冗余计算?

    @

    • @ 2022-12-17 20:08:40

      if (!(dep%2))
      return ((k*k)%mod)*a%mod

      @

      • @ 2022-12-17 19:52:43

        还是没过。。。。

        • 1

        Information

        ID
        171
        Time
        1000ms
        Memory
        256MiB
        Difficulty
        2
        Tags
        # Submissions
        518
        Accepted
        181
        Uploaded By