龟速乘

没什么好说的。板子:

#include<cstdio>
#define int long long
const int mod=1e18;

int times(int s1,int s2){
	if(s2==1)return s1;
	int an=times(s1,s2>>1);
	if(s2&1)return ((an+an)%mod+s1)%mod;
	else return (an+an)%mod;
}

signed main(){
	
	int s1=1e15+9,s2=1e15+9;
	printf("%lld\n%lld",s1*s2%mod,times(s1,s2));
	
	return 0;
}

输出

94944270305263697
18000000000000081

显然后者是对的。

posted @ 2022-06-21 15:26  Feyn618  阅读(23)  评论(0编辑  收藏  举报