
数论
文章平均质量分 92
数论
Guuuuuu老师儿
当初的算法竞赛题目博客的留言评论就不回复了,时间太久已经忘干净了,抱歉~
展开
-
xiaoxin juju needs help HDU - 5651 (有重复的全排列,逆元)
xiaoxin juju needs helpHDU - 5651As we all known, xiaoxin is a brilliant coder. He knew **palindromic** strings when he was only a six grade student at elementry school.This summer he was wo原创 2017-11-15 20:07:45 · 356 阅读 · 0 评论 -
3的幂的和 51Nod - 1013(快速幂+等比数列求和+逆元)
3的幂的和51Nod - 1013求:3^0 + 3^1 +...+ 3^(N) mod 1000000007 Input 输入一个数N(0 <= N <= 10^9) Output 输出:计算结果 Sample Input 3Sample Output 40思路:一开始都想到了用等比数列公式再加上一个快速幂取模求结果,但是提交上去就一直wa,后来听说要求逆元,但是还是不明白为什么要求...原创 2017-11-28 05:24:49 · 462 阅读 · 0 评论 -
Sumdiv POJ - 1845 (数论)
SumdivPOJ - 1845 Consider two natural numbers A and B. Let S be the sum of all natural divisors of A^B. Determine S modulo 9901 (the rest of the division of S by 9901).InputThe ...原创 2018-01-26 23:56:36 · 713 阅读 · 0 评论 -
Sum HDU - 4704(费马小定理降幂+快速幂模运算详解)
Sum HDU - 4704 ...原创 2018-04-09 15:48:53 · 934 阅读 · 0 评论 -
Bi-shoe and Phi-shoe LightOJ - 1370(筛素数,欧拉函数)
Bi-shoe and Phi-shoe LightOJ - 1370Bamboo Pole-vault is a massively popular sport in Xzhiland...原创 2018-04-09 21:28:11 · 229 阅读 · 0 评论 -
末尾零的个数(数论)
末尾零的个数N! 末尾有多少个 000 呢?N!=1×2×⋯×N里面讲到只有2和5遇到才会产生0(或者2的倍数和5的倍数)然是2的个数比5的多,所以只需要计算n中包含多少个5就行例如100100/5=20.。20/5=4.。4/5=0 所以100!有24个0不就是求5的个数嘛?为什么还不断循环除5呢?100/5不就是5的个数了嘛?其实不是的,我最初就有这个疑惑。...原创 2018-03-28 18:09:38 · 2966 阅读 · 1 评论 -
Prime Independence LightOJ - 1356(质因子分解+最大点独立集)
Prime Independence LightOJ - 1356A set of integers is called prime independent if none of its...原创 2018-04-16 16:38:51 · 652 阅读 · 0 评论 -
Aladdin and the Flying Carpet LightOJ - 1341(算数基本定理)
Aladdin and the Flying Carpet LightOJ - 1341 ...原创 2018-04-16 17:04:31 · 392 阅读 · 0 评论 -
C Looooops(扩展欧几里得)
H - C LooooopsTime Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64uSubmit Status Practice POJ 2115Appoint description: DescriptionA Compiler Mystery: We are given a C-langua...原创 2017-10-13 21:14:19 · 261 阅读 · 0 评论 -
A/B(HDU1576)(扩展欧几里得)
A/BTime Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2017 Accepted Submission(s): 1469Problem Description要求(A/B)%9973,但因为A非常大,我们仅仅给出n(n=A%9973)...原创 2017-10-13 19:44:20 · 478 阅读 · 0 评论 -
青蛙的约会(扩展欧几里得)
青蛙的约会 poj1061Time Limit: 1000MS Memory Limit: 10000KTotal S...原创 2017-10-13 18:23:51 · 265 阅读 · 0 评论 -
扩展欧几里得2(详解)
一开始学习扩展欧几里得发现学习了模板代码后,仍然不会做题,很多题要求的没有那么简单,而且涉及到了很多之前不知道的知识,因此首先先要补充一下可能会用到的知识:1、二元一次不定方程的一般形式为ax+by=c。其中 a,b,c 是整数,ab ≠ 0。此方程有整数解的充分必要条件是a、b的最大公约数整除c。设、是该方程的一组整数解,那么该方程的所有整数解可表示为。2、关于同余和模运算的一些总结: ...转载 2017-10-13 17:42:00 · 701 阅读 · 0 评论 -
双六问题(扩展欧几里得模板)
题目:一个双六上面有向前向后无限延续的格子,每个格子都写有整数。其中0号格子是起点,1 号格子是终点。而骰子上只有a,b,-a,-b四个整数,所以根据a和b的值的不同,有可能无法到达终点。现在的问题是掷出a,b,-a,-b各多少次可以达到终点呢? 输入:一行,包含两个数 a 和 b,两数之间用一个空格分隔,含义如题目所述。 输出:一个数,表示掷出四个整数次数的和,如果解不唯一,就...转载 2017-10-10 23:17:49 · 1106 阅读 · 0 评论 -
扩展欧几里得
gcd函数的基本性质:gcd(a,b)=gcd(b,a)=gcd(-a,b)=gcd(|a|,|b|)对于不完全为 0 的非负整数 a,b,gcd(a,b)表示 a,b 的最大公约数,必然存在整数对 x,y ,使得 gcd(a,b)=ax+by。求解 x,y的方法的理解设 a>b。1,显然当 b=0,gcd(a,b)=a。此时 x=1,y=0;2,a>b>0 时设 ax1+ by...转载 2017-10-10 20:46:29 · 232 阅读 · 0 评论 -
Modular Inverse ZOJ - 3609 (扩展欧几里得求逆元或者欧拉定理)
Modular Inverse ZOJ - 3609 The modular modular multiplicative inverse of an integer a modulo m is an integer x such that a-1≡x (mod m). ...原创 2018-04-22 14:45:38 · 347 阅读 · 0 评论 -
Harmonic Number (II) LightOJ - 1245 (找规律+数学)
Harmonic Number (II) LightOJ - 1245I was trying to solve problem '1234 - Harmonic Number', I wrote the following code ...原创 2018-04-23 08:27:06 · 594 阅读 · 0 评论 -
Position in Fraction (小数除法模拟)
Position in Fraction You have a fraction . You need to find the first occurrence of digit c into decimal notation of the fraction after decimal point. Input The fi...原创 2018-04-20 14:11:14 · 224 阅读 · 0 评论 -
Pairs Forming LCM LightOJ - 1236(整数唯一分解定理+筛选素数)
Pairs Forming LCM LightOJ - 1236Find the result of the following code: long long ...原创 2018-04-23 11:42:00 · 289 阅读 · 0 评论 -
Harmonic Number LightOJ - 1234(打表+技巧||调和级数逼近公式)
Harmonic Number LightOJ - 1234In mathematics, the nth harmonic number is the sum of the recip...原创 2018-04-23 14:52:15 · 384 阅读 · 0 评论 -
Mysterious Bacteria LightOJ - 1220(整数唯一分解定理+筛素数)
Mysterious Bacteria LightOJ - 1220Dr. Mob has just discovered a Deathly Bacteria. He named it...原创 2018-04-23 15:37:16 · 432 阅读 · 0 评论 -
Large Division LightOJ - 1214(模运算,数论水题)
Large Division LightOJ - 1214 ...原创 2018-04-23 15:51:36 · 293 阅读 · 0 评论 -
GCD of Polynomials (思维+数学)
GCD of PolynomialsSuppose you have two polynomials and . Then polynomial can be uniquely represented in the following way: This can be done using long division. Here, denotes the degree of polynomi...原创 2018-04-19 11:16:26 · 540 阅读 · 0 评论 -
Fantasy of a Summation LightOJ - 1213(找规律+快速幂)
Fantasy of a Summation LightOJ - 1213If you think codes, eat codes then sometimes you may get...原创 2018-04-23 16:55:45 · 223 阅读 · 0 评论 -
快速幂
快速幂的计算模板typedef long long ll;ll mod_pow(ll x, ll n, ll mod){ ll res = 1; while(n>0){ if(n&1)res = res * x % mod; x = x * x % mod; n >>= 1; ...转载 2017-10-10 16:53:17 · 187 阅读 · 0 评论 -
DNA Alignment CodeForces - 520C (思维+快速幂)
DNA Alignment CodeForces - 520CVasya became interested in bioinformatics. He's going to write an article about similar cyclic DNA...原创 2018-04-11 09:12:10 · 1065 阅读 · 1 评论 -
Sigma Function LightOJ - 1336(数论)
Sigma Function LightOJ - 1336 ...原创 2018-04-19 14:39:25 · 406 阅读 · 0 评论 -
Leading and Trailing LightOJ - 1282(数论)
Leading and Trailing LightOJ - 1282You are given two integers: n and k, your task is to find ...原创 2018-04-19 15:17:38 · 249 阅读 · 0 评论 -
Goldbach`s Conjecture LightOJ - 1259(筛素数)
Goldbach`s Conjecture LightOJ - 1259Goldbach's conjecture is one of the oldest unsolved probl...原创 2018-04-19 15:41:15 · 455 阅读 · 0 评论 -
CSU 1803 2016 (逆向思维+同余)
CSU 1803 2016 (逆向思维)为什么不能被2016整除的所有数和是这些呢如果a不能被2016整除有 a = k * 2016 + i所以小于a的不被2016整除的有k个,加上a本身就是+1cnt = k + 1 = (a - i) / 2016 + 1;那么对于n来说n以内余数是i的不能被2016整除的个数就有(n-i)/2016+1j同理code:#include <iostre...原创 2018-05-01 20:52:27 · 232 阅读 · 1 评论 -
GCD Expectation ZOJ - 3868 (容斥原理+快速幂)
GCD Expectation ZOJ - 3868 Edward has a set of n integers {a1, a2,...,an}. He randomly picks a nonempty subset {x1, x2,…,xm} (each nonemp...原创 2018-04-25 19:54:23 · 297 阅读 · 0 评论 -
Code Feat UVA - 11754(中国剩余定理+枚举)
Code Feat UVA - 11754题目链接题目大意:求一个数N,给出C和S,表示有C个条件,每个条件有X 和 k,然后是该个条件的k个yi,其中存在一个yjyjy_j使得N≡yi (mod X)N≡yi (mod X)N \equiv y_i \ (mod\ X),输出满足的最小的S个N,要求正整数。题目分析:根据题目我们知道...原创 2018-07-16 11:01:17 · 369 阅读 · 0 评论 -
Emoogle Grid UVA - 11916(BSGS)
Emoogle Grid UVA - 11916这道题需要求离散对数取模,具体的求解算法是BSGS算法 如果不了解,可以先看一下网上一篇博客写的很清楚BSGS算法题目意思:题意:要给M行N列的网格染上K种颜色,其中有B个不用染色,其他每个格子涂一种颜色,同一列上下两个格子不能染相同的颜色,给出M,N,K,和B个格子的位置,求出涂色的方案%100000007的结果是R,现在...原创 2018-07-17 21:58:23 · 265 阅读 · 0 评论 -
C Looooops POJ - 2115(扩展欧几里徳)
C Looooops POJ - 2115A Compiler Mystery: We are given a C-language style for loop of typefor (variable = A; variable != B; variable += C) statement;I.e., a loop which starts by setting varia...原创 2018-07-18 09:36:55 · 300 阅读 · 0 评论 -
Death to Binary? POJ - 2116(模拟+贪心)
Death to Binary? POJ - 2116The group of Absurd Calculation Maniacs has discovered a great new way how to count. Instead of using the ordinary decadic numbers, they use Fibonacci base numbers. Number...原创 2018-07-18 11:09:36 · 433 阅读 · 0 评论 -
Prime Time UVA - 10200(暴力打表+精度)
Prime Time UVA - 10200题意很简单求[a,b]中f(i)是素数的百分比我当时一看ab都不大可以直接暴力,也没想打表直接用了拉宾米勒素数测试,结果还是超时了,然后发现可以直接用最笨的方法判断只要打表就可以了,结果他妈精度卡的蛋疼,wa了十多发,最后要加一个esp! 以后做题涉及精度的得注意了,不行就得加esp!code:#include <iostre...原创 2018-07-19 15:42:56 · 542 阅读 · 0 评论 -
Farey Sequence POJ - 2478(欧拉函数)
Farey Sequence POJ - 2478The Farey Sequence Fn for any integer n with n >= 2 is the set of irreducible rational numbers a/b with 0 < a < b <= n and gcd(a,b) = 1 arranged in increasing or...原创 2018-07-19 17:06:33 · 195 阅读 · 0 评论 -
The Super Powers UVA - 11752(算数基本定理+枚举+细节)
The Super Powers UVA - 11752题意:我们称一个可以由至少两个不同的正整数的幂的形式表示的数称为超级幂。没有输入,让你输出1到264−11到264−11 到2^{64}-1之间的所有的超级幂。分析:根据算数基本定理,我们知道一个数可以分解成素数幂的乘积,那么既然一个数可以表示成某一个数的幂的形式那么肯定有(p1p2...pr)m(p1p2...pr)...原创 2018-07-19 20:06:06 · 427 阅读 · 0 评论 -
The equation SGU - 106(扩展欧几里得+解不等式)
The equation SGU - 106There is an equation ax + by + c = 0. Given a,b,c,x1,x2,y1,y2 you must determine, how many integer roots of this equation are satisfy to the following conditions : x1&lt;=x&lt;...原创 2018-07-19 21:35:57 · 633 阅读 · 0 评论 -
f(n) HDU 2582(找规律+筛素数+质因子分解详解)
HDU 2582 f(n) This time I need you to calculate the f(n) . (3<=n<=1000000)f(n)= Gcd(3)+Gcd(4)+…+Gcd(i)+…+Gcd(n).Gcd(n)=gcd(C[n][1],C[n][2],……,C[n][n-1])C[n][k] means the number of way to c...原创 2018-07-28 17:10:57 · 404 阅读 · 0 评论 -
Law of Commutation HDU - 6189(找规律+同余)
Law of Commutation HDU - 6189As we all know, operation ”+” complies with the commutative law. That is, if we arbitrarily select two integers a and b, a+b always equals to b+a. However, as for expone...原创 2018-07-15 09:54:21 · 265 阅读 · 0 评论