当前位置:网站首页>[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;
}
}
边栏推荐
- 27-31. Dependency transitivity, principle
- 【MySQL】数据库视图的介绍、作用、创建、查看、删除和修改(附练习题)
- QT qtablewidget table column top requirements ideas and codes
- Uniapp custom environment variables
- Impact relay jc-7/11/dc110v
- Which water in the environment needs water quality monitoring
- Sleep quality today 78 points
- C réaliser des jeux de serpents gourmands
- Leetcode question brushing record | 206_ Reverse linked list
- How to choose the middle-aged crisis of the testing post? Stick to it or find another way out? See below
猜你喜欢
Tree DP
Gridview出现滚动条,组件冲突,如何解决
Arcpy 利用updatelayer函数改变图层的符号系统
buuctf-pwn write-ups (8)
Abap:ooalv realizes the function of adding, deleting, modifying and checking
Learning multi-level structural information for small organ segmentation
JSON Web Token----JWT和傳統session登錄認證對比
Leetcode question brushing record | 206_ Reverse linked list
webrtc 快速搭建 视频通话 视频会议
My NVIDIA developer journey - optimizing graphics card performance
随机推荐
740. Delete and get points
Tree DP
27-31. Dependency transitivity, principle
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
C语言中的排序,实现从小到大的数字排序法
24 magicaccessorimpl can access the debugging of all methods
C realize Snake games
How to avoid JVM memory leakage?
4G wireless all network solar hydrological equipment power monitoring system bms110
Summary of leetcode BFS question brushing
Arcpy uses the updatelayer function to change the symbol system of the layer
ABAP:OOALV实现增删改查功能
The sorting in C language realizes the number sorting method from small to large
The solution of win11 taskbar right click without Task Manager - add win11 taskbar right click function
[Android reverse] function interception (CPU cache mechanism | CPU cache mechanism causes function interception failure)
2022.7.3-----leetcode. five hundred and fifty-six
2022.7.2-----leetcode.871
My NVIDIA developer journey - optimizing graphics card performance
Variables d'environnement personnalisées uniapp
APScheduler如何设置任务不并发(即第一个任务执行完再执行下一个)?