当前位置:网站首页>龟速乘【模板】
龟速乘【模板】
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;
}
边栏推荐
- 4.爬虫之Scrapy框架2数据解析&配置参数&数据持久化&提高Scrapy效率
- Controller层代码这么写,简洁又优雅!
- C# 中的Async 和 Await 的用法详解
- Selenium自动化测试之Selenium IDE
- [Niu Ke brush questions - SQL big factory interview questions] NO3. E-commerce scene (some east mall)
- 聊聊 SAP 产品 UI 上的消息显示机制
- Save and load numpy matrices and vectors, and use the saved vectors for similarity calculation
- selenium被反爬了怎么办?
- LeetCode·304竞赛·6132·使数组中所有元素都等于零·模拟·哈希
- C# List Usage List Introduction
猜你喜欢
IDEA的database使用教程(使用mysql数据库)
LeetCode·每日一题·1161.最大层内元素和·层次遍历
LeetCode·304竞赛·6132·使数组中所有元素都等于零·模拟·哈希
C#控件ListView用法
Centos7 install mysql5.7
抓住金三银四的尾巴,解锁程序员面试《刷题神器》
All-round visual monitoring of the Istio microservice governance grid (microservice architecture display, resource monitoring, traffic monitoring, link monitoring)
MATLAB | 我也做了一套绘图配色可视化模板
go使用makefile脚本编译应用
Even if the image is missing in a large area, it can also be repaired realistically. The new model CM-GAN takes into account the global structure and texture details
随机推荐
CLion用于STM32开发
TensorRT安装及使用教程「建议收藏」
Error IDEA Terminated with exit code 1
EasyMock日记1[通俗易懂]
csdn发文助手问题
最新完整代码:使用word2vec预训练模型进行增量训练(两种保存方式对应的两种加载方式)适用gensim各种版本
EXCEL如何快速拆分合并单元格数据
聊聊 SAP 产品 UI 上的消息显示机制
Text similarity calculation (Chinese and English) detailed explanation of actual combat
VU 非父子组件通信
Introduction to using NPM
Istio微服务治理网格的全方面可视化监控(微服务架构展示、资源监控、流量监控、链路监控)
操作符详解
C# List用法 List介绍
How IDEA runs web programs
C#使用NumericUpDown控件
Usage of += in C#
ECCV 2022 | 机器人的交互感知与物体操作
mysql8, starttime的下一个值作为endtime的上一个值?
PHP Serialization: eval