---
# System prepended metadata

title: exponentiation by squaring
tags: [codebook]

---

---
tags: codebook
---
{%hackmd theme-dark %}
# exponentiation by squaring
```cpp=
#include<iostream>
#include<limits>
using namespace std;
inline long long pow(long long a,long long b,long long m=numeric_limits<int>::max()){
	long long re;
	for(re=1;b;b>>=1,a=a*a%m)
		if(b&1) re=re*a%m;
	return re;
}
inline long long powi(const long long& a,const long long& b){
	if(!b) return 1;
	long long tmp=powi(a,b>>1);
	return (b&1?tmp*tmp*a:tmp*tmp);
}
int main(){
	cout<<pow(7,15)<<endl;
	return 0;
}
```