![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
数论
文章平均质量分 77
RadiumYang
ACM退役打牌选手
展开
-
斯特林公式
斯特林公式用于求n阶乘的近似值。n!的位数:lg(n!)=lg1+lg2+...+lgn向下取整+1;例题:Big NumberTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 41322 Accepted Submission(s):...原创 2018-04-07 22:29:14 · 385 阅读 · 0 评论 -
快速幂(例题:BZOJ1008)
在进行幂运算时一个一个乘需要耗费大量时间可以用一种类似二分的算法来快速运算,这就是快速幂。比如求x^n,n为偶数,x^n=(x^2)^(n/2),n为奇数,x^n=(x^2)^(n/2)*x;不停地分下去,知道n为0时停止。#include <iostream>typedef long long ll;using namespace std;ll mod_pow(ll...原创 2018-03-27 20:47:00 · 510 阅读 · 0 评论 -
素数求法
方法一:暴力求解(慢O(sqrt(n)))从2开始遍历到sqrt(n),如果有能除尽的则不是素数,否则则是素数,需要空间小,速度慢。#include <cstdio>#include <iostream>#include <cmath>using namespace std;int prime(int x){ if (x==0||x==1) ret...原创 2018-05-08 00:06:19 · 646 阅读 · 2 评论 -
算数基本定理(例题:LightOJ1341)
算数基本定理:基本形式:(Pn表示质数)导出结论(ACM中会用到的):1. (正因数个数)2. (正因数之和)例题:1341 - Aladdin and the Flying Carpet PDF (English)StatisticsForumTime Limit: 3 second(s)Memory Limit: 32 MBIt's said that Aladdin had ...原创 2018-05-31 23:45:24 · 308 阅读 · 0 评论 -
Lucas定理(求组合数,例题FZU2020,HDU3944)
Lucas定理:用于求C(n,m) mod p,其中p为素数证明等在网上都可以找到,我也不是很懂就略过了(懂了补上)。直接贴出用法吧:主要代码就两行,需要用到的知识有快速幂和求逆元(计算组合数),必要的时候需要打表(计算阶乘)快速幂:https://blog.csdn.net/Radium_1209/article/details/79718918核心代码: ll lu...原创 2018-08-25 20:52:40 · 553 阅读 · 0 评论 -
欧拉函数
打巧克力杯周赛的时候,遇到了一道欧拉函数板子题,然而我居然不会(数论全推给队友),结果是我居然用埃氏筛自己打出来了,居然还是对的。下面是那道题:例题:Farey Sequence LengthGiven a positive integer, NN, the sequence of all fractions a/ba/b with 0≤a≤b0≤a≤b, 1≤b≤N1≤b≤N a...原创 2018-12-05 23:47:16 · 124 阅读 · 0 评论