
数论
文章平均质量分 84
Apoised
我将一直前行,即使那时身边空无一人。
展开
-
欧拉函数
欧拉函数属于数论,计算小于n的数中与n互质的数的数目。通式: ,其中p1, p2……pn为x的所有质因数,x是不为0的整数。φ(1)=1(唯一和1互质的数(小于等于1)就是1本身)。 (注意:每种质因数只一个。比如12=2*2*3那么φ(12)=12*(1-1/2)*(1-1/3)=4)。模板1.直接求解欧拉函数int euler(int n){ i原创 2016-03-26 01:46:11 · 337 阅读 · 0 评论 -
欧几里德和扩展(hdu 1222)
欧几里德:求两个数的最大公约数。gcd(a,b) = gcd(b,a mod b)代码:int gcd(int x,int y){ return x%y==0?y:gcd(y,x%y);}扩展欧几里德:对于不完全为 0 的非负整数 a,b,gcd(a,b)表示 a,b 的最大公约数,必然存在整数对 x,y ,使得 gcd(a,b)=ax+by。用途:1.求不定方程:ax+by=c原创 2016-07-23 18:30:03 · 296 阅读 · 0 评论 -
Light OJ 1078:Integer Divisibility
同余定理(明天贴原图链接)1078 - Integer DivisibilityTime Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %lluSubmit StatusDescriptionIf an integer is not divisible by原创 2016-07-31 02:49:03 · 257 阅读 · 0 评论 -
LightOJ 1116
Ekka DokkaC - Ekka DokkaTime Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %lluDescriptionEkka and his friend Dokka decided to buy a cake. They both lo原创 2016-08-06 11:08:00 · 357 阅读 · 0 评论 -
LightOJ 1294
Positive Negative SignF - Positive Negative SignTime Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %lluDescriptionGiven two integers: n and m and n is di原创 2016-08-06 10:23:08 · 353 阅读 · 0 评论 -
尺取法
尺取法:对数组保存一对下标(起点,终点),然后根据实际情况交替推进两个端点直到得出答案。用于解决连续区间问题。eg:poj 3061 (也可以用二分)题意:给定长度为n的数列整数及S,求出总和不小于S的连续子序列的长度的最小值,不存在则输出1. input :n=10,S=15,a={5,1,3,5,10,7,4,9,2,8} otput:2(5+10)步原创 2016-08-11 15:45:23 · 309 阅读 · 0 评论