【 数论知识系统复习 】【 根据一本通提高篇总结 】【 待更 】

说在前面:

仔细阅读一本通提高篇,会发现它挺齐全的,综合了别的书籍的一些好的例题,还是很走心了。

习题配套,非常方便     配套习题:https://loj.ac/article/588   (不过网站容易炸飞 -_-? ,我们太强了?)

因为已经是自己的总结了 ∴会更切合考试——实用性强,方便复习。 (关闭两边的广告也OK)

欢迎━(*`∀´*)ノ亻! 因篇幅可能有点长,一点一点看也OK!质量有保证的哦!

 

第1章  快速幂

【  a^{b} % mod

不取模  版:

LL fast_cal (LL a,LL b,LL mod){
	LL ans=1;//赋值为1
	while (b){
		if (b&1)	ans*=a;
		a*=a;b>>=1;
	} 
	return ans; 
}

全代码:

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#define LL long long

using namespace std;

inline LL ll_wread(){
    char c=getchar ();LL flag=1,wans=0;
    while (c<'0'||c>'9'){if (c=='-') flag=-1;c=getchar ();}
    while (c>='0'&&c<='9'){wans=wans*10+c-'0';c=getchar ();}
    return wans*=flag;
}

LL fast_cal (LL a,LL b,LL mod){
	LL ans=1;//赋值为1
	while (b){
		if (b&1)	ans=(ans%mod*a%mod)%mod;
		a=(a%mod*a%mod)%mod;b>>=1;
	} 
	return ans%mod;//返回值时一定要取模
	// 特殊数据: 1 0 1 
	// 			即 1^0 % 1	Ans=0 
}

int main (){
	LL a=ll_wread() ,b=ll_wread(),mod=ll_wread();
	printf("%lld^%lld mod %lld=%lld\n",a,b,mod,fast_cal(a,b,mod));
	return 0;
}

luogu代码提交:https://www.luogu.org/problemnew/show/P1226

第1章 习题解析(全)(点击)

待更新...

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值