数论
数论
Herod_
这个作者很懒,什么都没留下…
展开
-
莫比乌斯函数性质以及反演公式
性质1:∑d∣n\sum_{d|n}∑d∣nμ(d)={1,if (n = 1)0,if (n > 1)\mu{(d)}=\begin{cases}1, & \text{if (n = 1)}\\0, & \text{if (n > 1)} \end{cases}μ(d)={1,0,if (n = 1)if (n > 1)性质2:.原创 2020-09-23 19:32:06 · 426 阅读 · 0 评论 -
UVA - 11426-GCD - Extreme (II)(欧拉函数应用)
GCD - Extreme (II)Given the value of N, you will have to find the value of G. The definition of G is given below:-------------------------------∑i=1i<N\sum_{i=1}^{i<N}∑i=1i<N∑j=i+1j<=N\sum_{j=i+1}^{j<=N}∑j=i+1j<=N GCD(i,j)------------原创 2020-09-08 19:05:38 · 146 阅读 · 0 评论 -
LightOJ-1197 Help Hanzo(区间筛板子题)
Help HanzoAmakusa, the evil spiritual leader has captured the beautiful princess Nakururu. The reason behind this is he had a little problem with Hanzo Hattori, the best ninja and the love of Nakururu. After hearing the news Hanzo got extremely angry. But原创 2020-09-08 14:00:55 · 248 阅读 · 0 评论 -
LightOJ-1236-Pairs Forming LCM(质因子分解)
Pairs Forming LCMFind the result of the following code:long long pairsFormLCM( int n ) { long long res = 0; for( int i = 1; i <= n; i++ ) for( int j = i; j <= n; j++ ) if( lcm(i, j) == n ) res++; // lcm means least common原创 2020-09-06 19:22:43 · 155 阅读 · 0 评论 -
POJ-1061-青蛙的约会(拓展欧几里得)
青蛙的约会两只青蛙在网上相识了,它们聊得很开心,于是觉得很有必要见一面。它们很高兴地发现它们住在同一条纬度线上,于是它们约定各自朝西跳,直到碰面为止。可是它们出发之前忘记了一件很重要的事情,既没有问清楚对方的特征,也没有约定见面的具体位置。不过青蛙们都是很乐观的,它们觉得只要一直朝着某个方向跳下去,总能碰到对方的。但是除非这两只青蛙在同一时间跳到同一点上,不然是永远都不可能碰面的。为了帮助这两只乐观的青蛙,你被要求写一个程序来判断这两只青蛙是否能够碰面,会在什么时候碰面。我们把这两只青蛙分别叫做青蛙A和原创 2020-09-06 17:50:25 · 152 阅读 · 0 评论 -
HDU-3307-Description has only two Sentences(欧拉定理)
Description has only two SentencesProblem Descriptionan = X*an-1 + Y and Y mod (X-1) = 0.Your task is to calculate the smallest positive integer k that ak mod a0 = 0.InputEach line will contain only three integers X, Y, a0 ( 1 < X < 231, 0 <=原创 2020-09-04 20:47:27 · 151 阅读 · 0 评论 -
LightOJ-1370-Bi-shoe and Phi-shoe(欧拉函数)
Bi-shoe and Phi-shoeBamboo Pole-vault is a massively popular sport in Xzhiland. And Master Phi-shoe is a very popular coach for his success. He needs some bamboos for his students, so he asked his assistant Bi-Shoe to go to the market and buy them. Plenty原创 2020-09-04 17:13:24 · 116 阅读 · 0 评论 -
小结:数论四大定理(威尔逊定理+欧拉定理+中国剩余定理+费马小定理)
前置知识:模运算消去律:ac ≡ bc (mod p) → a ≡ b (mod p/gcd(c,p) )威尔逊定理:当且仅当p为素数时,( p -1 )! ≡ -1 ( mod p )当且仅当p为素数时,( p -1 )! ≡ p-1 ( mod p )若p为质数,则p能被(p-1)!+1整除当且仅当p为素数时,p∣(p−1)!+1证明:https://brilliant.org/wiki/wilsons-theoremhttps://www.jianshu.com/p原创 2020-09-04 15:36:34 · 1107 阅读 · 1 评论 -
小结:欧拉函数
欧拉函数小结定义:给定正整数n,φ(n) = 不大于n且和n互质的正整数的个数(包括1)。如 φ(1)=1, φ(2)=1性质1:若p为素数,则 φ( p)=p-1 (显然,每个小于它的数都与它互质)性质2:若p为素数,正整数 n = pk 则 φ(n) = pk - pk-1 , 或写为 φ(n) = pk-1(p-1) = pk(1- 1p\frac{1}{p}p1)性质3:两个素数 p,q,正整数 n = p*q,则 φ(n) = (p-1)*(q-1)若正整数p,q互质,正整数原创 2020-09-04 14:51:59 · 164 阅读 · 0 评论 -
POJ-3696-The Luckiest number(欧拉定理+模消去律+快速幂/乘)
The Luckiest numberChinese 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 integers that are a multiple of L原创 2020-09-04 13:39:55 · 149 阅读 · 0 评论 -
HDU-5528-Count a * b(各种知识点)
推导:代码:#include <cstdio>#include <vector>#include <queue>#include <cstring>#include <cmath>#include <map>#include <set>#include <stack>#include <string>#include <iostream>#include <原创 2020-09-02 23:42:53 · 203 阅读 · 0 评论 -
POJ-2480-Longge‘s problem(欧拉函数)
Longge’s problemLongge is good at mathematics and he likes to think about hard mathematical problems which will be solved by some graceful algorithms. Now a problem comes: Given an integer N(1 < N < 2^31),you are to calculate ∑gcd(i, N) 1<=i <原创 2020-09-02 19:06:23 · 189 阅读 · 0 评论 -
HDU-4497-GCD and LCM(质因子分解+思维/组合数)
GCD and LCMProblem DescriptionGiven 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 divisor of x, y and z, whi原创 2020-09-02 02:30:54 · 149 阅读 · 0 评论 -
POJ-2142-The Balance(拓展欧几里得)
The BalanceMs. Iyo Kiffa-Australis has a balance and only two kinds of weights to measure a dose of medicine. For example, to measure 200mg of aspirin using 300mg weights and 700mg weights, she can put one 700mg weight on the side of the medicine and thre原创 2020-09-01 12:56:46 · 189 阅读 · 0 评论 -
模板:数论(持续更新)
ps:数大的时候 int全为long long素数筛:const int N = 1e7+15;int prime[N],mark[N],pcnt;// 如果变量名都相同的话,就不用传参了void getPrimes(int prime[],int N,int &pcnt){ memset(mark,0,sizeof(mark)); pcnt = 0; prime[pcnt++] = 2; mark[2] = 1; for(int i = 2;原创 2020-08-27 13:50:58 · 300 阅读 · 0 评论 -
开始数论学习
开始数论学习原创 2020-08-27 12:28:17 · 140 阅读 · 0 评论 -
ZOJ-3593-One Person Game(拓展欧几里得)
One Person GameThere is an interesting and simple one person game. Suppose there is a number axis under your feet. You are at point A at first and your aim is point B. There are 6 kinds of operations you can perform in one step. That is to go left or righ原创 2020-09-01 12:51:06 · 338 阅读 · 2 评论 -
HDU-2973-YAPTCHA(威尔逊定理)
YAPTCHAProblem DescriptionThe 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-to-Tell-Computers-and-Humans原创 2020-09-01 12:45:28 · 216 阅读 · 0 评论 -
HDU-1573-X问题(中国剩余定理+LCM)
X问题Problem Description求在小于等于N的正整数中有多少个X满足:X mod a[0] = b[0], X mod a[1] = b[1], X mod a[2] = b[2], …, X mod a[i] = b[i], … (0 < a[i] <= 10)。Input输入数据的第一行为一个正整数T,表示有T组测试数据。每组测试数据的第一行为两个正整数N,M (0 < N <= 1000,000,000 , 0 < M <= 10),表示X小于原创 2020-09-01 00:19:44 · 154 阅读 · 1 评论 -
POJ-2891-Strange Way to Express Integers(拓展中国剩余定理 模板题)
Strange Way to Express IntegersElina is reading a book written by Rujia Liu, which introduces a strange way to express non-negative integers. The way is described as following:Choose k different positive integers a1, a2, …, ak. For some non-negative m, d原创 2020-08-31 20:39:23 · 209 阅读 · 1 评论 -
HDU-4556-Stern-Brocot Tree(欧拉函数)
Stern-Brocot TreeProblem Description上图是一棵Stern-Brocot树,其生成规则如下: 从第1行到第n行,每行相邻两数a/b和c/d,产生中间数(a+c)/(b+d),置于下一行中。将一行的分数(包括0/1,1/0),进行约分简化,则每一行(包括0/1,1/0,1/1),不会出现两个相同的分数。若分子或者分母大于n,则去掉该分数,将剩下的分数,从小到大排序,得到数列F。 现在请您编程计算第n行的数列F的个数。Input输入包含多组测试用例,每组输入数原创 2020-08-31 19:33:26 · 515 阅读 · 0 评论 -
POJ-3090-Visible Lattice Points(欧拉函数)
Visible Lattice PointsA lattice point (x, y) in the first quadrant (x and y are integers greater than or equal to 0), other than the origin, is visible from the origin if the line from (0, 0) to (x, y) does not pass through any other lattice point. For ex原创 2020-08-31 19:07:08 · 121 阅读 · 0 评论 -
HDU-2815-Mod Tree(BSGS模板题)
Mod TreeProblem DescriptionThe picture indicates a tree, every node has 2 children.The depth of the nodes whose color is blue is 3; the depth of the node whose color is pink is 0.Now out problem is so easy, give you a tree that every nodes have K chil原创 2020-08-31 16:30:05 · 123 阅读 · 1 评论 -
HDU-6322-Euler Function(欧拉函数水题)
D. Euler FunctionProblem DescriptionIn number theory, Euler’s totient function φ(n) counts the positive integers up to a given integer n that are relatively prime to n. It can be defined more formally as the number of integers k in the range 1≤k≤n for wh原创 2020-08-31 15:18:09 · 137 阅读 · 0 评论 -
HDU-2421-Deciphering Password(质因子分解+积性函数)
Deciphering PasswordProblem DescriptionXiaoming has just come up with a new way for encryption, by calculating the key from a publicly viewable number in the following way:Let the public key N = AB, where 1 <= A, B <= 1000000, and a0, a1, a2, …, a原创 2020-08-31 14:51:29 · 168 阅读 · 0 评论 -
HDU-5584-LCM Walk(GCD/LCM)
题意:一只青蛙,站在x,y点,每次跳跃,会跳到,(x+lcm(x,y),y) 或者(x,y+lcm(y)) 点。现在给出终点,(exe_xex,eye_yey)求有多少个可能的起点。思路:乍一看好像每次又有两种可能,搜索起来复杂度很好。其实每次跳跃都是固定的。因为lcm(x,y)必然大于 x和y,那么显然上一步加的就是现在比较大的坐标。所以上一步的方向总是固定的。往回推的时候。如果 x>y 直接 swap(x,y) 方便计算现在假设上一步是 x,y那么 gcd(x,y) = d原创 2020-08-27 14:36:59 · 208 阅读 · 0 评论