1. 程式人生 > >codevs 2022 復仇 快速冪模版題

codevs 2022 復仇 快速冪模版題

codevs 2022 復仇 快速冪模版題

//
//  main.cpp
//  progress
//
//  Created by J__Max on 2018/10/19.
//  Copyright © 2018年 J__Max. All rights reserved.
//

#include <iostream>

using namespace std;

//快速冪
void solve
(int a, int b, int p){ long long int ans = 1, base = a; while (b != 0) { if((b & 1) != 0){ ans *= base; ans %= p; } base *= base; base %= p; b >>= 1; } cout<<ans<<endl; } int main(int argc, const char
* argv[]) { int a, b, p; cin>>a>>b>>p; solve(a, b, p); return 0; }