cpp_lib

This documentation is automatically generated by competitive-verifier/competitive-verifier

View the Project on GitHub idat50me/cpp_lib

:heavy_check_mark: Binary-Power(繰り返し二乗法) (math/binpow.cpp)

Verified with

Code

#pragma once

#ifndef call_include
#define call_include
#include <bits/stdc++.h>
using namespace std;
#endif

long long binpow(long long a, long long ex, long long p = (1LL << 61) - 1) {
	long long res = 1;
	while(ex > 0) {
		if(ex & 1) (res *= a) %= p;
		ex >>= 1;
		(a *= a) %= p;
	}
	return res;
}
#line 2 "math/binpow.cpp"

#ifndef call_include
#define call_include
#include <bits/stdc++.h>
using namespace std;
#endif

long long binpow(long long a, long long ex, long long p = (1LL << 61) - 1) {
	long long res = 1;
	while(ex > 0) {
		if(ex & 1) (res *= a) %= p;
		ex >>= 1;
		(a *= a) %= p;
	}
	return res;
}
Back to top page