跳到正文

个人记录

P1226 【模板】快速幂

yqzx0307约 1 分钟
原文
文章信息与版本

文章信息

发布
2026年2月7日
收录
2026年6月15日
更新
2026年11月14日
篇幅
约 1 分钟

版本

  1. v1当前
C++
#include <bits/stdc++.h>
using namespace std;
 #define int long long
 int qpow(int a,int b,int p)
 {
     int ans=1;
     while(b)
     {
         if(b&1)
         {
             ans*=a%p;
             ans%=p;
         }
         b>>=1;
         a*=a%p;
         a%=p;
     }
    return ans%p;
 }
signed main()
{
    int a,b,p;
    scanf("%lld%lld%lld",&a,&b,&p);
    int d=qpow(a,b,p);
    printf("%lld^%lld mod %lld=%lld",a,b,p,d);
    return 0;
}

https://www.luogu.com.cn/problem/P1226

原文