当前位置:网站首页>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;
}
边栏推荐
- GeoTrust ov multi domain SSL certificate is 2100 yuan a year. How many domain names does it contain?
- Geotrust OV Multi - Domain Domain SSL Certificate rmb2100 per year contains several Domain names?
- Major domestic quantitative trading platforms
- geotrust ov多域名ssl證書一年兩千一百元包含幾個域名?
- Go Chan's underlying principles
- UNET deployment based on deepstream
- Change deepin to Alibaba image source
- CorelDRAW graphics suite2022 free graphic design software
- 06 装饰(Decorator)模式
- Solution: the agent throws an exception error
猜你喜欢
Leetcode merge sort linked list
The underlying principle of go map (storage and capacity expansion)
Mysql表insert中文变?号的问题解决办法
Cannot activate CONDA virtual environment in vscode
Realize the function of data uploading
Ten thousand volumes are known to all, and one page of a book is always relevant. TVP reading club will take you through the reading puzzle!
Future trend of automated testing ----- self healing technology
UNET deployment based on deepstream
Go Chan's underlying principles
Learn AI safety monitoring project from zero [attach detailed code]
随机推荐
Super detailed pycharm tutorial
汇编语言中的标志位:CF、PF、AF、ZF、SF、TF、IF、DF、OF
oracle 存储过程与job任务设置
Go GC garbage collection notes (three color mark)
初学爬虫-笔趣阁爬虫
How to configure PostgreSQL 12.9 to allow remote connections
C language practice - number guessing game
How to recover deleted data in disk
Let genuine SMS pressure measurement open source code
ThinkPHP kernel work order system source code commercial open source version multi user + multi customer service + SMS + email notification
unable to execute xxx. SH: operation not permitted
Several methods of capturing packets under CS framework
Promise all()
二叉树解题(一)
Federal learning: dividing non IID samples according to Dirichlet distribution
Cache consistency solution - how to ensure the consistency between the cache and the data in the database when changing data
Vmware安装win10报错:operating system not found
Learn what definitelytyped is through the typescript development environment of SAP ui5
Idea automatic package import and automatic package deletion settings
LeetCode-归并排序链表