数学知识
数学
JdiLfc
这个作者很懒,什么都没留下…
展开
-
应用费马小定理快速求得大指数对p取模
费马小定理(Fermat’s little theorem)是数论中的一个重要定理,在1636年提出。如果p是一个质数,而整数a不是p的倍数,则有a^(p-1)≡1(mod p)。快速幂超时k = 998244353def fpow(a, b): ans = 1 while b > 0: if b % 2 == 1: ans = ans * a % k b //= 2 a = a * a % k原创 2020-12-13 23:03:49 · 481 阅读 · 0 评论 -
唯一分解定理一篇就够了
如果与唯一定理一起应用需要用到素数筛,可以看这篇文章:线性筛判断素数唯一分解定理:任何一个大于1的自然数 N,如果N不为质数,**那么N可以唯一分解成有限个质数的乘积:这里P1<P2<P3…<Pn均为质数,其中指数ai是正整数。这样的分解称为 N 的标准分解式。定理应用:3.用唯一分解求a,b的gcd,lcm(ak,bk为质数的幂):4.在不取mod的情况下,用唯一分解求组合数:解释:因子:如果a%b==0,就称b是a的因子,例如8的因子有: 1,2,4,8;原创 2020-11-04 16:01:26 · 4681 阅读 · 7 评论 -
C. Division--唯一分解定理
Oleg’s favorite subjects are History and Math, and his favorite branch of mathematics is division.To improve his division skills, Oleg came up with ????pairs of integers ???????? and ???????? and for each pair decided to find the greatest integer ???????原创 2020-11-03 21:31:43 · 624 阅读 · 1 评论 -
线性筛判断素数
线性筛存素数的数组不能开到1e7!!!【原始】时间复杂度O(n*sqrt(n))bool isprime(int n){ int i; for(i=2; i<=sqrt(n); i++) if(n%i==0) return false; return true;}【普通筛——埃拉托斯特尼(Eratosthenes)筛法】时间复杂度O(nloglogn)bool number[maxn+5];void isprime()原创 2020-10-24 15:55:25 · 477 阅读 · 1 评论