当前位置:网站首页>[number theory] fast power (Euler power)
[number theory] fast power (Euler power)
2022-07-04 06:30:00 【Nathan Qian】
subject

explain
- O(n∗logb)
Code segment
#include<iostream>
#define ll long long
using namespace std;
ll qmi(ll a,ll k,ll p)
{
ll res=1;
while(k)// Yes b Binarization , From low to high
{
// If b The binary representation of 0 Position as 1, Then multiply by the current a
if(k&1)res=res*a%p;
//b Moves to the right one
k>>=1;
// to update a,a In turn a^{2^0},a^{2^1},a^{2^2},....,a^{2^logb}
a=a*a%p;
}
return res;
}
int main()
{
int n;cin>>n;
while(n--)
{
ll a,k,p;
cin>>a>>k>>p;
cout<<qmi(a,k,p)<<endl;
}
}边栏推荐
- 《ClickHouse原理解析与应用实践》读书笔记(4)
- Detectron:训练自己的数据集——将自己的数据格式转换成COCO格式
- Overview of convolutional neural network structure optimization
- uniapp 自定義環境變量
- How to avoid JVM memory leakage?
- 2022.7.2-----leetcode.871
- Which water in the environment needs water quality monitoring
- QT 获取随机颜色值设置label背景色 代码
- C realize Snake games
- 采用中微BATG135实现IIC数据/指令交互
猜你喜欢

双色球案例

How to solve the component conflicts caused by scrollbars in GridView

雲原生——上雲必讀之SSH篇(常用於遠程登錄雲服務器)

High performance parallel programming and optimization | lesson 02 homework at home

How to realize multi account login of video platform members

QT 获取随机颜色值设置label背景色 代码

C # symmetric encryption (AES encryption) ciphertext results generated each time, different ideas, code sharing

Win10 clear quick access - leave no trace

R统计绘图-随机森林分类分析及物种丰度差异检验组合图

After the festival, a large number of people change careers. Is it still time to be 30? Listen to the experience of the past people
随机推荐
Learn about the Internet of things protocol WiFi ZigBee Bluetooth, etc. --- WiFi and WiFi protocols start from WiFi. What do we need to know about WiFi protocol itself?
分布式CAP理论
Which water in the environment needs water quality monitoring
C實現貪吃蛇小遊戲
My NVIDIA developer journey - optimizing graphics card performance
Summary of leetcode BFS question brushing
Realize IIC data / instruction interaction with micro batg135
Invalid revision: 3.18.1-g262b901-dirty
Matlab remainder
报错cvc-complex-type.2.4.a: 发现了以元素 ‘base-extension‘ 开头的无效内容。应以 ‘{layoutlib}‘ 之一开头。
Leakage detection relay jy82-2p
Compound nonlinear feedback control (2)
JS get the attribute values nested in the object
ORICO ORICO outdoor power experience, lightweight and portable, the most convenient office charging station
STM32 单片机ADC 电压计算
C realize Snake games
Appium基础 — APPium安装(二)
Experience weekly report no. 102 (July 4, 2022)
雲原生——上雲必讀之SSH篇(常用於遠程登錄雲服務器)
2022.7.2-----leetcode. eight hundred and seventy-one
