
ACM_数论
文章平均质量分 70
zzti_lhh
这个作者很懒,什么都没留下…
展开
-
【poj2142】The Balance(拓展欧几里得)
DescriptionMs. 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 ...原创 2018-04-30 11:37:50 · 368 阅读 · 2 评论 -
【poj2891】Strange Way to Express Integers(线性同余方程组)
DescriptionElina 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,...原创 2018-05-11 11:53:07 · 250 阅读 · 0 评论 -
【Light oj 1370】Bi-shoe and Phi-shoe(欧拉函数)
DescriptionBamboo 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 ...原创 2018-05-11 12:22:30 · 167 阅读 · 0 评论 -
数论之————欧拉函数
再讲欧拉函数之前,先讲一下欧拉定理。欧拉定理,也称费马-欧拉定理 若n,a为正整数,且n,a互质,即gcd(a,n) = 1,则 a^φ(n) ≡ 1 (mod n)。 ———————————————————————————————————————————————————— 这里的φ(n)就是欧拉函数。表达的意思是1到n-1内与n互质的数的个数。 正整数n的唯一分解式n=p1^a1*...原创 2018-05-11 15:02:19 · 594 阅读 · 0 评论 -
【hdu4135】Co-prime(容斥原理)
Problem DescriptionGiven a number N, you are asked to count the number of integers between A and B inclusive which are relatively prime to N. Two integers are said to be co-prime or relatively prim...原创 2018-05-18 19:37:43 · 198 阅读 · 0 评论 -
数论之————容斥原理
容斥原理是一种计数方法。这种方法的基本思想是:先不考虑重叠的情况,把包含于某内容中的所有对象的数目先计算出来,然后再把计数时重复计算的数目排斥出去,使得计算的结果既无遗漏又无重复举个例子 1.两个集合的情况 A,B是两个集合 所以连个集合的并:|A + B| = |A| + |B| - |AB| 2.三个集合的情况 三个集合的并:|A + B + C| = |A| + |...原创 2018-05-19 10:48:14 · 486 阅读 · 0 评论 -
数论之————素数
素数又叫质数,一个数除了1和他本身没有其他因子的叫素数。最一般的判断素数写法:bool prime(int x){ if(x<=1) return false; for(int i=2;i<x;i++) { if(x%i==0) return false; } return true;}快点的n开平方的复杂度...原创 2018-05-20 12:01:30 · 296 阅读 · 0 评论 -
【poj3070】Fibonacci(矩阵快速幂)
DescriptionIn the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = Fn − 1 + Fn − 2 for n ≥ 2. For example, the first ten terms of the Fibonacci sequence are:0, 1, 1, 2, 3, 5, 8, 13, 21, 34, …...原创 2018-05-14 21:32:36 · 187 阅读 · 0 评论 -
【hdu1005】Number Sequence(矩阵快速幂)
Problem DescriptionA number sequence is defined as follows:f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7.Given A, B, and n, you are to calculate the value of f(n).InputThe...原创 2018-05-14 22:00:27 · 330 阅读 · 0 评论 -
数论之————中国剩余定理
中国剩余定理 在《孙子算经》中有这样一个问题:“今有物不知其数,三三数之剩二(除以3余2),五五数之剩三(除以5余3),七七数之剩二(除以7余2),问物几何?”这个问题称为“孙子问题”,该问题的一般解法国际上称为“中国剩余定理”。首先,我们假设n1是满足除以3余2的一个数,也就是满足3∗k+2(k&amp;gt;=0)的一个任意数。同样,我们假设n2是满足除以5余3的一个数,n3是满足除以7...原创 2018-05-10 16:22:38 · 386 阅读 · 0 评论 -
【Lightoj1341】Aladdin and the Flying Carpet
It’s said that Aladdin had to solve seven mysteries before getting the Magical Lamp which summons a powerful Genie. Here we are concerned about the first mystery.Aladdin was about to enter to a magi...原创 2018-04-24 21:06:34 · 148 阅读 · 0 评论 -
【poj1995】Raising Modulo Numbers
DescriptionPeople are different. Some secretly read magazines full of interesting girls’ pictures, others create an A-bomb in their cellar, others like using Windows, and some like difficult mathema...原创 2018-04-30 12:22:56 · 223 阅读 · 0 评论 -
数论之————快速幂+矩阵快速幂
快速幂,顾名思义快速求一个数的次方。 为什么要用快速幂呢? 因为一般方法会超时,当次方很大的时候。 皮一下23333 ——————————————————————————————————————————————正文开始当n=2^k,那么x^n=((x^2)^2)….. 只要做k次平方运算就好了,现将n表示为2的幂次的和 得到 n=2^k1+2^k2+2^k3+….. 所...原创 2018-04-30 16:57:03 · 395 阅读 · 0 评论 -
数论之————逆元
数论倒数,又叫逆元逆元有什么用呢? 大家都知道 (a+b)%p=(a%p+b%p)%p (a-b)%p=(a%p-b%p)%p (a*b)%p=(a%p*b%p)%p 以上操作都是对的唯独到了除法不可以 比如:(8/2)%6=4!=(8%6)/(2%6)=1 对于有些题目需要中间过程取余,否则会超存储范,所以这时候就需要逆元了逆元的定义:方程ax≡1(mod p...原创 2018-05-01 13:17:23 · 612 阅读 · 0 评论 -
【hdu5685】Problem A(逆元)
Problem Description度熊手上有一本字典存储了大量的单词,有一次,他把所有单词组成了一个很长很长的字符串。现在麻烦来了,他忘记了原来的字符串都是什么,神奇的是他竟然记得原来那些字符串的哈希值。一个字符串的哈希值,由以下公式计算得到:H(s)=∏i≤len(s)i=1(Si−28) (mod 9973)Si代表 S[i] 字符的 ASCII 码。请帮助度熊计算大字符串...原创 2018-05-01 14:21:22 · 145 阅读 · 0 评论 -
【poj1061】青蛙约会
Description两只青蛙在网上相识了,它们聊得很开心,于是觉得很有必要见一面。它们很高兴地发现它们住在同一条纬度线上,于是它们约定各自朝西跳,直到碰面为止。可是它们出发之前忘记了一件很重要的事情,既没有问清楚对方的特征,也没有约定见面的具体位置。不过青蛙们都是很乐观的,它们觉得只要一直朝着某个方向跳下去,总能碰到对方的。但是除非这两只青蛙在同一时间跳到同一点上,不然是永远都不可能碰面的。为...原创 2018-04-24 12:31:11 · 192 阅读 · 0 评论 -
数论之————扩展欧几里得
一定存在整数对(x,y)使得ax+by=gcd(a,b) 求解ax+by=gcd(a,b) 一次递归之后 bx1+(a%b)y1=gcd(a,b) 这里有一点:a%b=a-(a/b)*b 带入上式得到 ay1+b(x1-(a/b)*y1)=gcd(a,b) 所以 ax+by=ay1+b(x1-(a/b)*y1) 所以 x=y1; y=x1-(a/b)*y1;代码:...原创 2018-04-24 12:58:04 · 248 阅读 · 0 评论 -
【poj1006】Biorhythms(中国剩余定理)
Description人生来就有三个生理周期,分别为体力、感情和智力周期,它们的周期长度为23天、28天和33天。每一个周期中有一天是高峰。在高峰这天,人会在相应的方面表现出色。例如,智力周期的高峰,人会思维敏捷,精力容易高度集中。因为三个周期的周长不同,所以通常三个周期的高峰不会落在同一天。对于每个人,我们想知道何时三个高峰落在同一天。对于每个周期,我们会给出从当前年份的第一天开始,到出现高...原创 2018-05-08 22:03:27 · 146 阅读 · 0 评论 -
【poj2115】C Looooops
DescriptionA Compiler Mystery: We are given a C-language style for loop of type for (variable = A; variable != B; variable += C)statement;I.e., a loop which starts by setting variable to value...原创 2018-04-24 15:29:27 · 137 阅读 · 0 评论 -
HDU【1576】A/B(逆元)
题目链接题解:因为A%9973/B%9973 != A/B%9973,所以要用到逆元,求出B关于9973的逆元,在乘n就行了(A/B=A乘B的逆元),我这里用的快速幂求逆元。不懂逆元的可以点这里代码:#include&amp;lt;iostream&amp;gt;#include&amp;lt;stdio.h&amp;gt;using namespace std;const int MOD=9973;typed...原创 2018-11-22 19:31:09 · 194 阅读 · 0 评论