A - Gregor and Cryptography
Gregor is learning about RSA cryptography, and although he doesn't understand how RSA works, he is now fascinated with prime numbers and factoring them.
Gregor's favori...
A - PizzaForces
PizzaForces is Petya's favorite pizzeria. PizzaForces makes and sells pizzas of three sizes: small pizzas consist of slices, medium ones consist of slices, and large pizzas consi...
A - Subsequence Permutation
A string of length , consisting of lowercase letters of the English alphabet, is given.
You must choose some number between and . Then, you select characters of an...
B1 - Wonderful Coloring - 1
This is a simplified version of the problem B2. Perhaps you should read the problem B2 before you start solving B1.
Paul and Mary have a favorite string which consists...
快速幂
原理
复杂度:
只要把指数位拆分,就可以实现复杂度的骤减。
实现思路
拆分二进制,取出每一位上的值。(移位)
如果值为 1 ,则乘。
实现代码
int fast_pow(int a, int b) {
int ans = 1, base = a;
while (b > 0) {
if (b & 1) ans *= base;
...