当前位置:网站首页>龟速乘【模板】
龟速乘【模板】
2022-07-31 13:28:00 【秦小咩】
龟速乘用于较大数乘法,因为较大数的乘法会容易爆范围,故采用“安全加法换乘法,时间换空间”的龟速乘。当然也可以不用龟速乘,在容易爆范围的地方强制转换__int128位即可
代码如下,规律是,一个乘数做底,一个做指数,乘法变加法
# include<iostream>
# include<iomanip>
# include<math.h>
using namespace std;
typedef long long int ll;
# define mod 10007
ll quick(ll a,ll b)
{
ll sum=0,pow=b;
while(pow)
{
if(pow&1)
sum=(sum+a)%mod;
a=(a+a)%mod;
pow>>=1;
}
return sum%mod;
}
int main ()
{
int a,b;
cin>>a>>b;
cout<<quick(a,b);
return 0;
}
边栏推荐
猜你喜欢
随机推荐
golang-gin-优雅重启
What should I do if selenium is reversed?
机器学习模型验证:被低估的重要一环
Usage of += in C#
代码随想录笔记_哈希_454四数相加II
C#控件ListView用法
自制的数据库安全攻防题,相关靶机自己制作
Save and load numpy matrices and vectors, and use the saved vectors for similarity calculation
Istio微服务治理网格的全方面可视化监控(微服务架构展示、资源监控、流量监控、链路监控)
Spark Learning: Add Custom Optimization Rules for Spark Sql
技能大赛训练题:交换机的远程管理
P5019 [NOIP2018 提高组] 铺设道路
ECCV2022: Recursion on Transformer without adding parameters and less computation!
365-day challenge LeetCode1000 questions - Day 044 Maximum element in the layer and level traversal
基于去噪自编码器的故障隔离与识别方法
拥塞控制,CDN,端到端
[Niu Ke brush questions - SQL big factory interview questions] NO3. E-commerce scene (some east mall)
C# control StatusStrip use
Error: npm ERR code EPERM
C#Assembly的使用








