当前位置:网站首页>[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;
}
}边栏推荐
- JS execution mechanism
- [March 3, 2019] MAC starts redis
- 198. House raiding
- How to use multithreading to export excel under massive data? Source code attached!
- Learning multi-level structural information for small organ segmentation
- ES6 模块化
- 对List进行排序工具类,可以对字符串排序
- STC8H开发(十二): I2C驱动AT24C08,AT24C32系列EEPROM存储
- Displaying currency in Indian numbering format
- The width of the picture in rich text used by wechat applet exceeds the problem
猜你喜欢

Cloud native - SSH article that must be read on the cloud (commonly used for remote login to ECS)

Variables d'environnement personnalisées uniapp

Which water in the environment needs water quality monitoring

【问题记录】03 连接MySQL数据库提示:1040 Too many connections

Functions in C language (detailed explanation)

A little understanding of GSLB (global server load balance) technology

【无标题】

QT qtablewidget table column top requirements ideas and codes

uniapp 自定義環境變量
![[Android reverse] function interception (CPU cache mechanism | CPU cache mechanism causes function interception failure)](/img/7e/02bb01480257cd56537914a7247733.jpg)
[Android reverse] function interception (CPU cache mechanism | CPU cache mechanism causes function interception failure)
随机推荐
AWT common components, FileDialog file selection box
198. House raiding
High performance parallel programming and optimization | lesson 02 homework at home
Cloud native - SSH article that must be read on the cloud (commonly used for remote login to ECS)
How to choose the middle-aged crisis of the testing post? Stick to it or find another way out? See below
C realize Snake games
实用的小工具指令
QT qtablewidget table column top requirements ideas and codes
ABAP:OOALV实现增删改查功能
Abap:ooalv realizes the function of adding, deleting, modifying and checking
C實現貪吃蛇小遊戲
Which water in the environment needs water quality monitoring
R统计绘图-随机森林分类分析及物种丰度差异检验组合图
Internet of things protocol ZigBee ZigBee module uses the concept of protocol stack
[openvino+paddle] paddle detection / OCR / SEG export based on paddle2onnx
4G wireless all network solar hydrological equipment power monitoring system bms110
C实现贪吃蛇小游戏
FRP intranet penetration, reverse proxy
SQL join, left join, right join usage
[untitled]
