当前位置:网站首页>龟速乘【模板】
龟速乘【模板】
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;
}
边栏推荐
猜你喜欢
网络协议及相关技术详解
A detailed explanation of the usage of Async and Await in C#
Introduction to using NPM
IDEA连接MySQL数据库并执行SQL查询操作
LeetCode·304竞赛·6132·使数组中所有元素都等于零·模拟·哈希
20.nn.Module
IDEA can't find the Database solution
The operator,
EXCEL如何快速拆分合并单元格数据
Grab the tail of gold, silver and silver, unlock the programmer interview "Artifact of Brushing Questions"
随机推荐
The cluster of safe mode
IDEA连接MySQL数据库并执行SQL查询操作
Samba 远程命令执行漏洞(CVE-2017-7494)
Spark学习:为Spark Sql添加自定义优化规则
/run/NetworkManager占用空间过大
Use of C# Assembly
ERROR 1819 (HY000) Your password does not satisfy the current policy requirements
Usage of += in C#
战略进攻能力的重要性,要远远高于战略防守能力
SAP 电商云 Spartacus SSR Optimization Engine 几处 timeout 的执行顺序
PHP序列化:eval
最新完整代码:使用word2vec预训练模型进行增量训练(两种保存方式对应的两种加载方式)适用gensim各种版本
中望3D 2023正式发布,设计仿真制造一体化缩短产品开发周期
页面整屏滚动效果
基于高阶微分器的无模型滑模控制器及其在自动电压调节器中的应用
go使用makefile脚本编译应用
golang-gin - graceful restart
报错:npm ERR code EPERM
The importance of strategic offensive capability is much higher than strategic defensive capability
Buffer 与 拥塞控制