Topic Link: Click to open the link
Test instructions: n^m%1000000007 N (1 <= n <= 10^15),m (1 <= m <= 10^12)
A little pit. n Too much can overflow, pow_mod (n,m,mod) =pow (n%mod,m,mod)
Deduce it ...
N^m%mod= (n%mod+k*mod) ^m%mod=[(n%mod) ^m +: A bunch of mods]%mod = (n%mod) ^m%mod
Haven't hit the code for ages .... Qaq
Hardware to get out of the Xiang ... All day long hold the video to see how people write how to write ... Various circuit diagrams fly in the sky ..... It's like a yard farm.
The fact proves that the algorithm is difficult to say. At least it's not forgotten .... 233333333333
#include <algorithm> #include <iostream> #include <cstring> #include <cstdlib> #include < string> #include <cctype> #include <vector> #include <cstdio> #include <cmath> #include < queue> #include <stack> #include <map> #include <set> #define MAXN 10000002#define _ll __int64# Define ll long long#define INF 0x3f3f3f3f#define Mod 1000000007#define pp pair<int,int> #define ull unsigned long lon Gusing namespace Std;ll pow_mod (ll a,ll n,ll p) {if (n==0) return 1;ll ans=pow_mod (a,n/2,p); Ans=ans*ans%p;if (n%2==1) ans= Ans*a%p;return ans;} ll N,m;int Main () {while (~scanf ("%lld%lld", &n,&m)) printf ("%lld\n", Pow_mod (N%mod,m,mod)); return 0;}
Sdut 3097-Xiao Xin Love math (Fast power)