![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
数论
coldfresh
那我们开始吧
展开
-
【CodeForces - 1154G】Minimum Possible LCM(涉及数论很多东西。。)
You are given an array a consisting of n integers a1,a2,…,an.Your problem is to find such pair of indices i,j (1≤i<j≤n) that lcm(ai,aj) is minimum possible.lcm(x,y) is the least common multiple o...原创 2019-05-09 19:20:00 · 351 阅读 · 0 评论 -
若干式子的证明
一些定理: 1.设f,gf,gf,g为两个数论函数,ttt为完全积性函数,若:f(n)=∑i=1nt(i)g(⌊ni⌋)f(n)=∑i=1nt(i)g(⌊ni⌋)f(n)=\sum_{i=1}^nt(i)g(\lfloor \frac{n}{i}\rfloor) 则:g(n)=∑i=1nμ(i)t(i)f(⌊ni⌋)g(n)=∑i=1nμ(i)t(i)f(⌊ni⌋)g(n)=\sum_{i=1...原创 2018-07-27 16:10:05 · 461 阅读 · 0 评论 -
【51nod 1222】 最小公倍数计数
**题目来源: Project Euler 基准时间限制:6 秒 空间限制:131072 KB 分值: 640 难度:8级算法题** 定义F(n)表示最小公倍数为n的二元组的数量。 即:如果存在两个数(二元组)X,Y(X &amp;amp;amp;amp;lt;= Y),它们的最小公倍数为N,则F(n)的计数加1。 例如:F(6) = 5,因为[2,3] [1,6] [2,6] [3,6] [6,6]的最小公倍数等于6...原创 2018-07-30 20:09:32 · 324 阅读 · 0 评论 -
今天让我们来学一学积性函数的筛法
第一件事情我们要知道的是:积性函数都可以线性筛。(就是说复杂度是O(n)O(n)O(n) 积性函数的性质不说了,在说说常见的几个积性函数。 μ(n)μ(n)\mu(n):莫比乌斯函数 ϕ(n)ϕ(n)\phi(n):欧拉函数 d(n)d(n)d(n):一个数n的约数个数 σ(n)σ(n)σ(n):一个数n的约数和那我们就来筛筛看吧,(注意:所有线性筛积性函数都必须基于线性筛素数。 ...原创 2018-07-22 18:24:11 · 447 阅读 · 0 评论 -
素数的线性欧拉筛
先上代码:#define maxx 400005using namespace std;int prime[100005];bool p[maxx];int cnt=0;void init(){ for(int i=2;i&amp;lt;maxx;i++) { if(!p[i]) prime[cnt++]=i; ...原创 2018-07-22 15:10:39 · 311 阅读 · 0 评论 -
【51nod 1227】 平均最小公倍数(杜教筛)
题目来源: Project Euler 基准时间限制:1.5 秒 空间限制:131072 KB 分值: 640 难度:8级算法题 重点内容 Lcm(a,b)表示a和b的最小公倍数,A(n)表示Lcm(n,i)的平均数(1 &amp;lt;= i &amp;lt;= n), 例如:A(4) = (Lcm(1,4) + Lcm(2,4) + Lcm(3,4) + Lcm(4,4)) / 4 = (4 + 4 +...原创 2018-07-29 21:07:24 · 435 阅读 · 0 评论 -
【51nod1237】 最大公约数之和 V3 (杜教筛)
基准时间限制:5 秒 空间限制:262144 KB 分值: 640 难度:8级算法题 给出一个数N,输出小于等于N的所有数,两两之间的最大公约数之和。相当于计算这段程序(程序中的gcd(i,j)表示i与j的最大公约数): 由于结果很大,输出Mod 1000000007的结果。G=0; for(i=1;i<=N;i++) for(j=1;j<=N;j++) { ...原创 2018-07-29 20:03:14 · 458 阅读 · 0 评论 -
【51nod 1238】 最小公倍数之和 V3(杜教筛)
基准时间限制:8 秒 空间限制:262144 KB 分值: 640 难度:8级算法题 收藏 关注 出一个数N,输出小于等于N的所有数,两两之间的最小公倍数之和。相当于计算这段程序(程序中的lcm(i,j)表示i与j的最小公倍数): 由于结果很大,输出Mod 1000000007的结果。G=0; for(i=1;i&amp;amp;amp;amp;amp;amp;amp;lt;=N;i++) for(j=1;j&amp;amp;amp;amp;amp;amp;原创 2018-07-29 18:22:14 · 428 阅读 · 0 评论 -
关于一些函数求前缀和的问题
1.设f(n)f(n)f(n)为n的因子的和,求: ∑i=1nf(i)∑i=1nf(i)\sum_{i=1}^nf(i) 其中n&amp;amp;lt;1012n&amp;amp;lt;1012nans=∑in∑jn[j|i]∗j=∑jnj∑in[j|i]=∑j=1n⌊nj⌋ans=∑in∑jn[j|i]∗j=∑jnj∑in[j|i]=∑j=1n⌊nj⌋ans=\sum_i^n\sum_j^n[j|i]*j\\=\sum_j...原创 2018-07-24 20:38:55 · 430 阅读 · 0 评论 -
【51nod 1244】 莫比乌斯函数之和 (杜教筛)
莫比乌斯函数,由德国数学家和天文学家莫比乌斯提出。梅滕斯(Mertens)首先使用μ(n)(miu(n))作为莫比乌斯函数的记号。具体定义如下: 如果一个数包含平方因子,那么miu(n) = 0。例如:miu(4), miu(12), miu(18) = 0。 如果一个数不包含平方因子,并且有k个不同的质因子,那么miu(n) = (-1)^k。例如:miu(2), miu(3), miu(3...原创 2018-07-27 17:01:38 · 621 阅读 · 0 评论 -
【51nod 1239】 欧拉函数之和(杜教筛)
基准时间限制:3 秒 空间限制:131072 KB 分值: 320 难度:7级算法题 对正整数n,欧拉函数是小于或等于n的数中与n互质的数的数目。此函数以其首名研究者欧拉命名,它又称为Euler’s totient function、φ函数、欧拉商数等。例如:φ(8) = 4(Phi(8) = 4),因为1,3,5,7均和8互质。 S(n) = Phi(1) + Phi(2) + …… Ph...原创 2018-07-27 18:57:33 · 382 阅读 · 0 评论 -
【51nod 1189】 阶乘分数 (数论)
题目来源: Spoj 基准时间限制:1 秒 空间限制:131072 KB 分值: 80 难度:5级算法题 1/N!=1/X+1/Y(0<x<=y)1/N!=1/X+1/Y(0<x<=y)1/N! = 1/X + 1/Y(01k=1x+1yxy=k(x+y)k2=(k−x)(k−y)1k=1x+1yxy=k(x+y)k2=(k−x)(k−y)\frac{1}{k}=\fr...原创 2018-09-07 15:52:55 · 300 阅读 · 0 评论 -
【HDU 5528】Count a * b(推导)
Problem Description Marry likes to count the number of ways to choose two non-negative integers a and b less than m to makea×ba×b a×b mod m≠0m≠0m≠0.Let’s denotef(m)f(m) f(m) as the number of ways ...原创 2018-08-29 17:32:48 · 829 阅读 · 0 评论 -
【51nod】Gcd and Phi(反演)
基准时间限制:2 秒 空间限制:131072 KB 分值: 320 F(n)=∑ni=1∑nj=1ϕ(ϕi,ϕj)F(n)=∑i=1n∑j=1nϕ(ϕi,ϕj) F(n)=∑_{i=1}^n∑_{j=1}^nϕ(ϕ_i,ϕ_j) 其中 ϕ 表示欧拉函数。欧拉函数ϕn 是不超过n的数中与n互质的数的数目。 ϕ(ϕi,ϕj) 表示i,j欧拉函数值的最大公约数的欧拉函数值.给出n,求F(n...原创 2018-08-28 21:23:04 · 396 阅读 · 0 评论 -
【51nod】 寻找分数(数学)
基准时间限制:1 秒 空间限制:131072 KB 分值: 160 给出 a,b,c,d, 找一个分数p/q,使得a/b < p/q < c/d,并且q最小。例如:1/3同1/2之间,符合条件且分母最小的分数是2/5。(如果q相同,输出p最小的) Input 第1行:一个数T,表示后面用作输入测试的数的数量。(1 <= T <= 10000) 第2 - T + 1行...原创 2018-08-28 17:58:07 · 428 阅读 · 0 评论 -
【51nod】最大公约数之和(简单数论或者积性)
给出一个n,求1-n这n个数,同n的最大公约数的和。比如:n = 6 1,2,3,4,5,6 同6的最大公约数分别为1,2,3,2,1,6,加在一起 = 15 Input 1个数N(N &amp;lt;= 10^9) Output 公约数之和 Input示例 6 Output示例 15 思路:先转化成数学公式: ans=∑i=1ngcd(i,n)ans=∑i=1ngcd(i,n)an...原创 2018-08-28 15:28:16 · 693 阅读 · 0 评论 -
【Timus 1132】 Square Root(二次同余)
上代码:#include&lt;iostream&gt;#include&lt;cstdio&gt;#include&lt;cmath&gt;#include&lt;algorithm&gt;#define ll long longusing namespace std;ll P(ll a,ll b,ll mod){ ll ans=1; w原创 2018-08-14 17:34:13 · 446 阅读 · 0 评论 -
计算模m的k次根
已知:k,b,mk,b,mk,b,m 求解同余式:xk≡b(mod m)xk≡b(mod m)x^k\equiv b(mod\ m)如果我们满足两个限制 1.gcd(b,m)=1gcd(b,m)=1gcd(b,m)=1 2.gcd(k,ϕ(m))=1gcd(k,ϕ(m))=1gcd(k,\phi(m))=1 那么我们是有快速的方法求解x的1.先计算ϕ(m)ϕ(m...原创 2018-08-14 10:48:43 · 429 阅读 · 0 评论 -
【HDU 5608】function(杜教筛)
Problem Description There is a function f(x),which is defined on the natural numbers set N,satisfies the following eqautionN2−3N+2=∑d|Nf(d)N2−3N+2=∑d|Nf(d)N^2−3N+2=\sum_{d|N}f(d)calulate ∑ni=1f(i...原创 2018-07-27 21:03:18 · 272 阅读 · 0 评论 -
17年ACM/ICPC亚洲区域赛现场赛乌鲁木齐站(D题和K题)
这次在乌市现场赛的关键是D题和K题,就这两个问题来实际探讨一下。 就比赛前一刻,我突然想起前1到n的平方和1到n的平方和,然后我问东东通向公式是多少,最后我还是想起来,但是没想到,在比赛的时候还真的用着了。这是题外话,咳咳。 由于题目资源放在计蒜客平台上,而且要到明年2月才开放,所以只能拿自己在现场赛的纸质题目了… D题: 题目大意就是在一个圆上,在其圆周上放置n个点,问最多原创 2017-12-16 22:50:59 · 1057 阅读 · 0 评论 -
Super A^B mod C FZU - 1759 (欧拉降幂)
Given A,B,C, You should quickly calculate the result ofABmodCABmodC A^B mod C. (1<=A,C<=1000000000,1<=B<=101000000).(1<=A,C<=1000000000,1<=B<=101000000).(1原创 2018-04-12 16:44:21 · 348 阅读 · 0 评论 -
Pagodas HDU - 5512 (数论)
n pagodas were standing erect in Hong Jue Si between the Niushou Mountain and the Yuntai Mountain, labelled from 1 to n. However, only two of them (labelled a and b, where 1≤a≠b≤n) withstood the test ...原创 2018-04-04 17:54:35 · 234 阅读 · 0 评论 -
HeHe HDU - 2879(积性)
In the equation X^2≡X(mod N) where x∈[0,N-1], we define He[N] as the number of solutions. And furthermore, define HeHe[N]=He[1]*……*He[N] Now here is the problem, write a program, output HeHe[N] mod原创 2017-10-17 23:54:55 · 312 阅读 · 0 评论 -
GCD HDU - 2588(欧拉函数)
The greatest common divisor GCD(a,b) of two positive integers a and b,sometimes written (a,b),is the largest divisor common to a and b,For example,(1,2)=1,(12,18)=6. (a,b) can be easily found by the原创 2017-09-29 23:20:00 · 446 阅读 · 0 评论 -
Sticks and Right Triangle HDU - 3939(毕达哥拉斯)
We have a stick with infinite length. Now we want to cut 3 sub-sticks with length x, y, z which is not large than L to form a right triangle. With unknown reasons we assume that x, y, z are all integer原创 2017-09-29 19:08:53 · 307 阅读 · 0 评论 -
Prime Distance POJ - 2689 (素数)
The branch of mathematics called number theory is about properties of numbers. One of the areas that has captured the interest of number theoreticians for thousands of years is the question of primalit原创 2017-09-27 14:46:31 · 310 阅读 · 0 评论 -
Zball in Tina Town HDU - 5391 (威尔逊定理)
Tina Town is a friendly place. People there care about each other. Tina has a ball called zball. Zball is magic. It grows larger every day. On the first day, it becomes 1 time as large as its original原创 2017-09-26 14:28:12 · 334 阅读 · 0 评论 -
YAPTCHA HDU - 2973 (威尔逊定理)
The math department has been having problems lately. Due to immense amount of unsolicited automated programs which were crawling across their pages, they decided to put Yet-Another-Public-Turing-Test-t原创 2017-09-26 14:03:25 · 337 阅读 · 0 评论 -
Squarefree number HDU - 3826(数论)
In mathematics, a squarefree number is one which is divisible by no perfect squares, except 1. For example, 10 is square-free but 18 is not, as it is divisible by 9 = 3^2. Now you need to determine whe原创 2017-09-25 13:10:43 · 552 阅读 · 0 评论 -
The Luckiest number POJ - 3696 (欧拉函数)
Chinese people think of ‘8’ as the lucky digit. Bob also likes digit ‘8’. Moreover, Bob has his own lucky number L. Now he wants to construct his luckiest number which is the minimum among all positive原创 2017-06-07 21:29:16 · 379 阅读 · 0 评论 -
无法表示的数 51Nod - 1176
z = (x/2)取整后 + y + xy,x,y都是大于0的整数。z=[x2]+y+xyz=[\frac{x}{2}]+y+xyx,y取不同的数,z可能有多种表示方式,也可能一种都没有,比如3,15就无法用任何x,y来表示。现在将所有无法表示的数排个序,组成一个序列S,给出一个整数n,你来求Snn = ?。比如n = 1,Snn = 1,n = 2,Snn = 3……,由于Snn可能很大,只输出原创 2017-10-18 00:25:12 · 362 阅读 · 0 评论 -
Special Prime HDU - 2866(数论)
Give you a prime number p, if you could find some natural number (0 is not inclusive) n and m, satisfy the following expression: We call this p a “Special Prime”. AekdyCoin want you to tell him the原创 2017-09-30 16:00:44 · 436 阅读 · 0 评论 -
(pat)A1059. Prime Factors
Given any positive integer N, you are supposed to find all of its prime factors, and write them in the format N = p1^k1 * p2^k2 *…*pm^km.Input Specification:Each input file contains one test case ...原创 2018-03-09 11:40:37 · 209 阅读 · 0 评论 -
Digital Square HDU - 4394 (数论)(DFS)
Given an integer N,you should come up with the minimum nonnegative integer M.M meets the follow condition: M2mod10x=nM^2 mod 10^x=n(x=0,1,2,3….) Input The first line has an integer T( T< = 1000), th原创 2017-10-16 00:18:10 · 316 阅读 · 0 评论 -
Diophantus of Alexandria HDU - 1299(数论)
Diophantus of Alexandria was an egypt mathematician living in Alexandria. He was one of the first mathematicians to study equations where variables were restricted to integral values. In honor of him,原创 2017-10-12 23:01:56 · 271 阅读 · 0 评论 -
最小公倍数之和 V2 51Nod - 1190(莫比乌斯反演)
给出2个数a, b,求LCM(a,b) + LCM(a+1,b) + .. + LCM(b,b)。 例如:a = 1, b = 6,1,2,3,4,5,6 同6的最小公倍数分别为6,6,6,12,30,6,加在一起 = 66。 由于结果可能很大,输出Mod 10^9 + 7的结果。(测试数据为随机数据,没有构造特别坑人的Test) Input 第1行:一个数T,表示后面用作输入测试的数的数量原创 2017-10-19 15:57:41 · 338 阅读 · 0 评论 -
Ignatius's puzzle HDU - 1098 (中国剩余+扩欧)
Ignatius is poor at math,he falls across a puzzle problem,so he has no choice but to appeal to Eddy. this problem describes that:f(x)=5*x^13+13*x^5+k*a*x,input a nonegative integer k(k<10000),to find t原创 2017-09-30 22:24:32 · 352 阅读 · 0 评论 -
GCD and LCM HDU - 4497 (唯一分解定理)
Given two positive integers G and L, could you tell me how many solutions of (x, y, z) there are, satisfying that gcd(x, y, z) = G and lcm(x, y, z) = L? Note, gcd(x, y, z) means the greatest common d原创 2017-09-30 20:18:18 · 528 阅读 · 0 评论 -
Harry Potter and the Hide Story HDU - 3988 (数论)
iSea is tired of writing the story of Harry Potter, so, lucky you, solving the following problem is enough. Input The first line contains a single integer T, indicating the number of test cases. E原创 2017-09-30 17:44:25 · 331 阅读 · 0 评论 -
Number Theory (Easy) SPOJ - NUMTRYE(数论)(结论类)
f(n) and g(n) are two functions defined as following :f(n)=∏(pi2ei+1+1)f(n) = ∏( pi^{2e_i+1}+1 ), where pi is prime factor of n and ei is highest power of pi in n.g(n)=Σ(ngcd(n,i))g(n) = Σ( \frac{n}{gc原创 2017-10-18 12:42:39 · 318 阅读 · 0 评论