当前位置:网站首页>[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;
}
}
边栏推荐
- [untitled]
- 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
- Json Web token - jwt vs. Traditional session login Authentication
- JS execution mechanism
- 实用的小工具指令
- 【问题记录】03 连接MySQL数据库提示:1040 Too many connections
- MySQL information_ Schema database
- 报错cvc-complex-type.2.4.a: 发现了以元素 ‘base-extension‘ 开头的无效内容。应以 ‘{layoutlib}‘ 之一开头。
- Software keywords and process information intercepted by Golden Shield video player
- Grounding relay dd-1/60
猜你喜欢
A little understanding of GSLB (global server load balance) technology
webrtc 快速搭建 视频通话 视频会议
双色球案例
Reading notes of Clickhouse principle analysis and Application Practice (4)
JSON web token -- comparison between JWT and traditional session login authentication
剑指 Offer II 038. 每日温度
Another company raised the price of SAIC Roewe new energy products from March 1
How to avoid JVM memory leakage?
Uniapp custom environment variables
27-31. Dependency transitivity, principle
随机推荐
STC8H开发(十二): I2C驱动AT24C08,AT24C32系列EEPROM存储
How does apscheduler set tasks not to be concurrent (that is, execute the next task after the first one)?
7. Agency mode
Grounding relay dd-1/60
Learning multi-level structural information for small organ segmentation
运算符<< >>傻瓜式测试用例
Is the insurance annuity product worth buying? Is there a hole?
JS execution mechanism
uniapp 自定义环境变量
ORICO ORICO outdoor power experience, lightweight and portable, the most convenient office charging station
Notes and notes
Stc8h development (XII): I2C drive AT24C08, at24c32 series EEPROM storage
C语言中的函数(详解)
Experience weekly report no. 102 (July 4, 2022)
JSON web token -- comparison between JWT and traditional session login authentication
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
How to solve the component conflicts caused by scrollbars in GridView
Win10 clear quick access - leave no trace
Arcpy 利用updatelayer函数改变图层的符号系统
Impact relay jc-7/11/dc110v