
数论
爱吃老谈酸菜的DV
选择适合自己的。
展开
-
miller_rabin素数判定+Pollard-rho素因子分解
一、miller_rabin素数判定miller_rabin是一种素性测试算法,用来判断一个大数是否是一个质数。miller_rabin是一种随机算法,它有一定概率出错,设测试次数为s,那么出错的概率是 4^(−s)算法的理论基础:Fermat定理:若a是任意正整数(1≤ a≤ n−1),n是奇素数,则 a^(n-1) ≡ 1 mod n。如果n是一个奇素数,将n−1表示成2^s*r 的...原创 2020-02-22 17:57:50 · 496 阅读 · 0 评论 -
poj2800 Joseph's Problem
DiscriptionJoseph likes taking part in programming contests. His favorite problem is, of course, Joseph’s problem.It is stated as follows.There are n persons numbered from 0 to n - 1 standing in a ...原创 2020-02-11 22:58:06 · 187 阅读 · 0 评论 -
UVA - 1404 Prime k-tuple【筛素数】
discription{p1, . . . , pk : p1 < p2 < . . . < pk} is called a prime k-tuple of distance s if p1, p2, . . . , pk are consecutiveprime numbers and pk − p1 = s. For example, with k = 4, s = 8...原创 2020-02-11 21:02:11 · 267 阅读 · 0 评论 -
Uva 10061 进制问题【公式推导】
DiscriptionGiven a decimal integer number you will have to find out how many trailing zeros will be there in itsfactorial in a given number system and also you will have to find how many digits will...原创 2020-02-08 22:45:53 · 290 阅读 · 2 评论 -
三角函数公式
一、三角函数定义式sinA=a/csinA=a/c sinA=a/ccosA=b/c cosA=b/ccosA=b/ctanA=a/btanA=a/btanA=a/bcotA=b/acotA=b/acotA=b/asecA=c/bsecA=c/bsecA=c/bcscA=c/acscA=c/acscA=c/a二、同角三角函数基本关系1.倒数关系tanAcotA=1tanAcot...原创 2020-02-08 21:19:32 · 888 阅读 · 0 评论 -
POJ 2689【筛法求素数+区间筛素数】
DiscriptionThe branch of mathematics called number theory is about properties of numbers. One of the areas thathas captured the interest of number theoreticians for thousands of years is the questio...原创 2020-02-08 20:49:51 · 205 阅读 · 0 评论 -
Stirling公式【求解N!的位数】
一、定义斯特林公式(Stirling’s approximation)是一条用来取n的阶乘的近似值的数学公式。一般来说,当n很大的时候,n阶乘的计算量十分大,所以斯特林公式十分好用,而且,即使在n很小的时候,斯特林公式的取值已经十分准确。Stirling公式.:n!≈sqrt(2∗pi∗n)∗[(n/e)n]n!≈sqrt(2*pi*n)*[(n/e)^n]n!≈sqrt(2∗pi∗n)∗[...原创 2020-02-07 23:29:49 · 457 阅读 · 0 评论 -
POJ - 1320:Street Numbers【佩尔方程】
DriscriptionA computer programmer lives in a street with houses numbered consecutively (from 1) down one sideof the street. Every evening she walks her dog by leaving her house and randomly turning ...原创 2020-02-04 18:26:04 · 244 阅读 · 0 评论 -
佩尔方程
佩尔方程,是一种不定二次方程。Pell方程,古希腊和印度的数学家对此类方程的研究做了最早的贡献,由费马首先进行了深入研究,拉格朗日给出了解决方案,但后此类方程来却被欧拉误记为佩尔提出,并写入他的著作中。后人多称佩尔方程。原创 2020-02-03 21:58:59 · 1710 阅读 · 0 评论 -
UVA10090 Marbles【扩展的欧几里得】
DiscriptionI have some (say, n) marbles (small glass balls) and I am going to buy some boxes to store them. Theboxes are of two types:T ype 1: each box costs c1 Taka and can hold exactly n1 marbles...转载 2020-02-02 18:07:57 · 229 阅读 · 0 评论 -
UVA - 10951 Polynomial GCD 【最大公共多项式】
DisctiptionGiven a decimal integer number you will have to find out how many trailing zeros will be there in itsfactorial in a given number system and also you will have to find how many digits will...原创 2020-02-02 16:50:44 · 259 阅读 · 0 评论 -
求最大公共多项式
定义1 若h(x)既是f(x)的因式,又是g(x)的因式,则称h(x)是f(x)与g(x)的公因式。 因,c|f(x),c|g(x),并且c!=0,所以任意两个多项式都有公因式。定义2设d(x)是f(x)与g(x)的一个公因式,如果对于f(x)与g(x)的 任一个公因式h(x),都有h(x)|d(x)则称d(x)是f(x)与g(x)的一个最大公因式。定理如果d(x)是f(x)与g(x)的...原创 2020-02-02 16:22:59 · 806 阅读 · 0 评论 -
SDAU数论练习五-F【贪心】
DiscriptionOn one of the Caribbean Islands there are N tourists and you want to move them from this island to another one.There are only two boats on this island, the first one can hold n1 tourists ...原创 2020-01-31 16:22:53 · 364 阅读 · 0 评论 -
Codeforces 7C Line【扩展的欧几里得】
DiscriptionA line on the plane is described by an equation Ax + By + C = 0. You are to find any point on this line, whose coordinates are integer numbers from - 5·1018 to 5·1018 inclusive, or to fin...原创 2020-01-31 15:23:30 · 333 阅读 · 0 评论 -
容斥原理、鸽笼原理
一、容斥定理定义:在计数时,必须注意没有重复,没有遗漏。为了使重叠部分不被重复计算,人们研究出一种新的计数方法。这种方法的基本思想是:先不考虑重叠的情况,把包含于某内容中的所有对象的数目先计算出来,然后再把计数时重复计算的数目排斥出去,使得计算的结果既无遗漏又无重复。这种计数的方法称为容斥原理。举个例子:有A、B两个集合,如图:会发现求AUB时,A+B对AB加了两次,所以再减去一次...原创 2020-01-30 15:35:21 · 842 阅读 · 0 评论 -
Restoring Number【找规律,有坑】
DiscriptionPavel had two positive integers a and b. He found their sum s and greatest common divisor g, and forgot a and b after that. Help him to restore the original numbers.InputA single line co...原创 2020-01-29 21:47:41 · 283 阅读 · 0 评论 -
求一个数所有因子个数和因子和
一、求一个数所有因子个数若能整除i,则不断除i,并记录i的次数。则除到最后存在两种情况当x == 1,这说明 x 没有其他因子了,得到答案;当x != 1, 这时 x 为其一个素数因子(且这个因子大于 根号x ),所以结果最后再乘2,得到因子个数。///求一个数所有因子的个数(包括1和它本身)ll countnum(ll x) { ll ans=1; for(ll i...原创 2020-01-27 23:22:55 · 1449 阅读 · 0 评论 -
POJ -3641Pseudoprime numbers【筛素数+快速幂+欧拉函数降幂】
DisciptionFermat’s theorem states that for any prime number p and for any integer a > 1, a^p = a (mod p). That is, if we raise a to the pth power and divide by p, the remainder is a. Some (but not...原创 2020-01-27 19:46:03 · 233 阅读 · 0 评论 -
SDAU数论练习四-I(我也不知道题号是啥,没搜到)【打表预处理】
DiscriptionI will show you the most popular board game in the Shanghai Ingress Resistance Team.It all started several months ago.We found out the home address of the enlightened agent Icount2three ...原创 2020-01-22 21:53:46 · 244 阅读 · 0 评论 -
hdu6441 Find Integer
Discriptionpeople in USSS love math very much, and there is a famous math problem .give you two integers n,a,you are required to find 2 integers b,c such that a^n + b^n= c^n.Inputone line contain...原创 2020-01-21 15:44:12 · 197 阅读 · 0 评论 -
本原勾股数组
本原勾股数组是指一个自然数三元组(a,b,c),其中a,b,c没有公因数,且满足a² +b² =c²。a,b奇偶性不同,且c是奇数若a是奇数,令a=st;则b=(s²-t²)/2;c = (s²+t²)/2。其中s>t>=1是没有公因数的奇数c-b与c+b总是平方数,并且c-b与c+b没有公因数。证明:假设有公因数,设d是c-b与c+b的公因数,则d也整除(c+b)+(...原创 2020-01-21 15:37:29 · 1546 阅读 · 0 评论 -
杜教筛模板
资源来源杜教筛还看不太懂,先转载大佬博客求杜教筛μ和φ#include<bits/stdc++.h>#include<tr1/unordered_map>#define N 6000010using namespace std;template<typename T>inline void read(T &x){ x=0; ...转载 2020-01-19 12:08:11 · 152 阅读 · 0 评论 -
莫比乌斯反演入门
一、引入假设有两个函数F(n),f(d),且d∈{x| x|n(即n被d整除)}并有以下关系:F(n)等于所有f(d)之和。即二、推导【μ(d)】由公式得到:F(1)=f(1)F(2)=f(1)+f(2)F(3)=f(1)+ f(3)F(4)=f(1)+f(2)+f(4)F(5)=f(1)+f(5)F(6)=f(1)+f(2)+f(3)+f(6)进而:f(1)=F(1...原创 2020-01-18 15:57:56 · 237 阅读 · 0 评论 -
K - GCD Again【欧拉函数】
DiscriptionDo you have spent some time to think and try to solve those unsolved problem after one ACM contest?No? Oh, you must do this when you want to become a “Big Cattle”.Now you will find that ...原创 2020-01-15 20:56:25 · 358 阅读 · 0 评论 -
C - GCD【化简+欧拉定理】
DiscriptionThe 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 fo...原创 2020-01-15 20:47:40 · 385 阅读 · 0 评论 -
H - Description has only two Sentences【推导+欧拉定理】
Discriptiona n = X*a n-1 + Y and Y mod (X-1) = 0.Your task is to calculate the smallest positive integer k that a k mod a 0 = 0.InputEach line will contain only three integers X, Y, a 0 ( 1 < X...原创 2020-01-15 16:08:27 · 239 阅读 · 0 评论 -
G - Calculation【欧拉公式降幂】
DiscriptionAssume that f(0) = 1 and 0^0=1, f(n) = (n%10)^f(n/10) for all n bigger than zero. Please calculate f(n)%m. (2 ≤ n , m ≤ 10^9, x^y means the y th power of x).InputThe first line contains ...原创 2020-01-15 15:38:04 · 316 阅读 · 0 评论 -
快速乘、快速幂、大数快速幂、矩阵快速幂模板
一、快速乘long long mul(long long a,long long b,log long p){ long long ans=0; for(;b;b>>=1) { if(b&1) ans=(ans+a)%p; a=a*2%p; } return ans;}二、...原创 2019-07-26 10:10:28 · 231 阅读 · 0 评论 -
B - HeHe【规律+积性函数+筛法求素数】
DiscriptionIn 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 He...原创 2020-01-14 10:35:13 · 259 阅读 · 0 评论 -
I - How many integers can you find【容斥定理】
DiscriptionNow you get a number N, and a M-integers set, you should find out how many integers which are small than N, that they can divided exactly by any integers in the set. For example, N=12, and...原创 2020-01-13 19:45:46 · 128 阅读 · 0 评论 -
HDU - 2619 Love you Ten thousand years【原根】
DiscriptionLove you Ten thousand years------Earth’s rotation is a day that is the representative of a day I love you. True love, there is no limit and no defects. Earth’s revolution once a year, it i...原创 2019-12-21 17:15:44 · 165 阅读 · 0 评论 -
原根
一、定义设m > 1 且 gcd(a, m) = 1, 则使得a^t ≡ 1(mod m) 成立的最小的正整数t称为a对模m的阶, 记为δm(a)。如果a的阶(mod m)为ϕ(m), 则称a为m的一个原根。 即若δm(a)=ϕ(m), 则称a为m的一个原根。二、定理定理1:若g是m的一个原根,则 g,g2,⋯,gϕ(m)各数对模m的最小剩余,恰是小于m且与m互素的ϕ(m)个正整数...原创 2019-12-21 17:11:19 · 219 阅读 · 0 评论 -
HDU1788 【中国剩余定理】
Discription我知道部分同学最近在看中国剩余定理,就这个定理本身,还是比较简单的:假设m1,m2,…,mk两两互素,则下面同余方程组:x≡a1(mod m1)x≡a2(mod m2)…x≡ak(mod mk)在0<=<m1m2…mk内有唯一解。记Mi=M/mi(1<=i<=k),因为(Mi,mi)=1,故有二个整数pi,qi满足Mipi+miqi=1...原创 2019-12-21 16:59:24 · 685 阅读 · 0 评论 -
HDU 2136【筛法打表】
DiscriptionEverybody knows any number can be combined by the prime number.Now, your task is telling me what position of the largest prime factor.The position of prime 2 is 1, prime 3 is 2, and prim...原创 2019-12-21 16:55:07 · 133 阅读 · 0 评论 -
HDU 12151:七夕节
描述七夕节那天,月老来到数字王国,他在城门上贴了一张告示,并且和数字王国的人们说:“你们想知道你们的另一半是谁吗?那就按照告示上的方法去找吧!”人们纷纷来到告示前,都想知道谁才是自己的另一半.告示如下:数字N的因子就是所有比N小又能被N整除的所有正整数,如12的因子有1,2,3,4,6.你想知道你的另一半吗?Input输入数据的第一行是一个数字T(1<=T<=500000...原创 2019-12-21 16:50:31 · 172 阅读 · 0 评论 -
HDU1825【唯一分解定理+积性函数】
DiscriptionAs we all know, the next Olympic Games will be held in Beijing in 2008. So the year 2008 seems a little special somehow. You are looking forward to it, too, aren’t you? Unfortunately there...原创 2019-12-21 16:47:00 · 178 阅读 · 0 评论 -
HDU1792A New Change Problem【打表找规律】
DescriptionNow given two kinds of coins A and B,which satisfy that GCD(A,B)=1.Here you can assume that there are enough coins for both kinds.Please calculate the maximal value that you cannot pay and...原创 2019-12-21 16:33:00 · 311 阅读 · 0 评论 -
HDU 2197:本原串
描述由0和1组成的串中,不能表示为由几个相同的较小的串连接成的串,称为本原串,有多少个长为n(n<=100000000)的本原串?答案mod2008.例如,100100不是本原串,因为他是由两个100组成,而1101是本原串。Input输入包括多个数据,每个数据一行,包括一个整数n,代表串的长度。Output对于每个测试数据,输出一行,代表有多少个符合要求本原串,答案mod20...原创 2019-12-21 16:23:16 · 184 阅读 · 0 评论 -
HDU 2104:丢手绢【判断是否互质】
DiscriptionThe Children’s Day has passed for some days .Has you remembered something happened at your childhood? I remembered I often played a game called hide handkerchief with my friends.Now I int...原创 2019-12-21 16:12:41 · 170 阅读 · 0 评论 -
HDU 5019:revenge of GCD【GCD】
DiscriptionNow given two kinds of coins A and B,which satisfy that GCD(A,B)=1.Here you can assume that there are enough coins for both kinds.Please calculate the maximal value that you cannot pay and...原创 2019-12-21 16:06:19 · 161 阅读 · 0 评论