当前位置:网站首页>Mathematical knowledge: fast power fast power
Mathematical knowledge: fast power fast power
2022-06-23 07:45:00 【Fight! Sao Nian!】
subject :AcWing 875. Fast power
Given n Group ai,bi,pi, For each set of data , Find out aibimod pi Value .
Input format
The first line contains integers n.
Next n That's ok , Each line contains three integers ai,bi,pi.
Output format
For each set of data , Output a result , Express aibimod pi Value .
Each result takes up one line .
Data range
1≤n≤100000,
1≤ai,bi,pi≤2×109
sample input :
2
3 2 5
4 3 9
sample output :
4
1
Topic analysis :
seek aibimod pi
Preprocess first :
a Of 20 Power mod p
a Of 21 Power mod p
…
a Of 2logk Power mod p
And then bi Power conversion to x20+x21+…x2logk
This is the use of binary properties
#include <iostream>
using namespace std;
const int N = 100010;
typedef long long LL;
LL qmi(int a,int k,int p)
{
LL res=1%p;
while(k)
{
if(k&1)res=(LL)res*a%p;
a=(LL)a*a%p;
k>>=1;
}
return res;
}
int main()
{
int n;
scanf("%d",&n);
while(n--)
{
int a,k,p;
scanf("%d%d%d",&a,&k,&p);
cout<<qmi(a,k,p)<<endl;
}
return 0;
}
边栏推荐
- leetcode210. Schedule II 207 Curriculum topology sorting DFS BFS
- 一篇文章学会er图绘制
- . H5 file forgets the database name and uses h5py to print
- Solutions to abnormal network connection of Xiaoai speakers
- [pyqt5 series] modify the counter to realize control
- 浅谈ThreadLocal和InheritableThreadLocal,源码解析
- JS to determine the added and decreased elements of two arrays
- Heuristic search strategy
- RTMP streaming exception fast recovery scheme
- Download the OSS file and modify the file name
猜你喜欢

【云计算赛项】职业技能竞赛--容器开发部分例题Pig快速开发框架

WPS for thesis writing installs MathType plug-in to write mathematical formulas

How to quickly and gracefully download large files from Google cloud disk (II)

User mode and kernel mode

Qt工程报错:-1: error: Cannot run compiler ‘clang++‘. Output:mingw32-make.exe

What is customer experience automation?
![[深度学习][原创]如何不用yolov5权重或者模型进行目标检测和绘制map等参数图](/img/f3/ff14cb5439a24e26f977e5f0d15785.png)
[深度学习][原创]如何不用yolov5权重或者模型进行目标检测和绘制map等参数图

测试apk-异常管控NetTraffic攻击者开发

YGG 西班牙 subDAO——Ola GG 正式成立

The sandbox has reached a cooperation with football player to bring popular football cartoons and animation into the metauniverse
随机推荐
Both are hard disk partitions. What is the difference between C disk and D disk?
利用for循环输出一个字母三角形
聊聊服务治理中的路由设计
浅谈ThreadLocal和InheritableThreadLocal,源码解析
RTMP streaming exception fast recovery scheme
How bootstrap clears floating styles
Operation on a bit of binary
Focusing on the industry, enabling customers | release of solutions for the five industries of the cloud container cloud product family
NFS special attention to permissions
Tri rapide + Tri par bulle + Tri par insertion + Tri par sélection
Realization of rolling broadcast effect
Unity audio visualization scheme
Pseudocode specification, pseudocode online editor,
1278_FreeRTOS_借助prvAddCurrentTaskToDelayedList接口理解delayed task
【markdown】markdown 教程大归纳
three. Solution to stripe shadow and grid shadow in JS
电脑如何安装MySQL?
YGG 西班牙 subDAO——Ola GG 正式成立
Wechat multiplayer chat and Roulette Games (websocket Implementation)
Deploy kubersphere in kubernetes