![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
数论
awayfrommea
hurry up
展开
-
2022年上学期程序设计实践练习-1(数学,枚举)
B.求最小公倍数 lcm(a,b)=a*b/gcd(a,b) ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; } 错误代码: if(res%ans==0||ans%res==0) ans=max(ans,res); else ans=res*ans; lcm(6,28)原创 2022-03-24 00:00:49 · 796 阅读 · 0 评论 -
数论 逆元
逆元定义:若整数 b,m 互质,并且b|a,则存在一个整数 x,使得 a/b≡a×x(mod m),则称 x 为 b 的模 m 乘法逆元,记为 b−1(mod m)。 最后两步:a≡a mod (m) 推出 bx≡1(mod m) 如果不为1,则矛盾 所以最后即解同余方程bx≡1(mod m) 求法: m为质数时:快速幂 b的m-2次方 m不是质数:利用扩展欧几里得定理求解同余方程bx≡1(mod m) 等价于 bx+my=1 逆元作用:不希望做除法 用逆元来替代分母,求逆元的过程中也只用到分母,与分子原创 2022-02-10 17:51:47 · 974 阅读 · 0 评论