当前位置:网站首页>Mathematical knowledge -- understanding and examples of fast power
Mathematical knowledge -- understanding and examples of fast power
2022-07-02 04:52:00 【Wu Yu 4】
Fast power : Find out quickly a^k mod p Result .
1<=a,k,p<=1e9.
The fast power is actually Preprocessing come out :
therefore a^k It can be expressed as ( Binary representation ):
Explain : come out a^(2^0)=a outside , The rest of the pretreatment has been in square .
Example :875. Fast power - AcWing Question bank
Topic :
Code :
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
int qmi(int a,int k,int p)
{
int res=1;
while(k)
{
if(k&1) res=(ll)res*a%p;
k>>=1;
a=(ll) a*a%p;
}
return res;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
while(n--)
{
int a,k,p;
cin>>a>>k>>p;
cout<<qmi(a,k,p)<<endl;
}
return 0;
}
边栏推荐
- Orthogonal test method and function diagram method for test case design
- How to modify data file path in DM database
- Pytest learning ----- pytest assertion of interface automation testing
- 06 装饰(Decorator)模式
- C language practice - binary search (half search)
- 数学知识——快速幂的理解及例题
- 二叉树解题(二)
- [high speed bus] Introduction to jesd204b
- Rhcsa --- work on the third day
- Typescript function details
猜你喜欢
Its appearance makes competitors tremble. Interpretation of Sony vision-s 02 products
数据库问题汇总
Change deepin to Alibaba image source
June book news | 9 new books are listed, with a strong lineup and eyes closed!
培养中小学生对教育机器人的热爱之心
Future trend of automated testing ----- self healing technology
Markdown edit syntax
06 decorator mode
My first experience of shadowless cloud computer
Deeply understand the concepts of synchronization and asynchrony, blocking and non blocking, parallel and serial
随机推荐
Interview question: do you know the difference between deep copy and shallow copy? What is a reference copy?
C language practice - number guessing game
The underlying principle of go map (storage and capacity expansion)
农业生态领域智能机器人的应用
Let正版短信测压开源源码
[understand one article] FD_ Use of set
CY7C68013A之keil编译代码
DC-1靶场搭建及渗透实战详细过程(DC靶场系列)
二叉樹解題(二)
Why can't you remember when reading? Why can't you remember- My technology learning methodology
Win10 disk management compressed volume cannot be started
Precipitate yourself and stay up late to sort out 100 knowledge points of interface testing professional literacy
Thinkphp Kernel wo system source Commercial Open source multi - user + multi - Customer Service + SMS + email notification
MySQL table insert Chinese change? Solution to the problem of No
The solution to the complexity brought by lambda expression
奠定少儿编程成为基础学科的原理
One step implementation of yolox helmet detection (combined with oak intelligent depth camera)
记录一次Unity 2020.3.31f1的bug
6月书讯 | 9本新书上市,阵容强大,闭眼入!
win10 磁盘管理 压缩卷 无法启动问题