![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
----------数论
mfcheer
他不停地跑啊跑 就为了追上那个曾经被寄予厚望的自己
展开
-
LightOJ 1067 - Combinations【Lucas定理】
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1067题意: 组合数求模,Lucas定理代码:#include <stdio.h> #include <math.h> #include <stdlib.h> #include <algorithm> #include <string.h> #include原创 2016-03-14 08:46:07 · 596 阅读 · 0 评论 -
我是好人 【欧几里得定理的性质】
Description 众所周知,我是好人!所以不会出太难的题,题意很简单 给你两个数n和m,问你有多少对正整数对最大公约数是n,最小公倍数是m最后友情提供解题代码(我真是太好人了)void solve(){long long n, m;scanf(“%lld%lld”, &n, &m);int ans = 0;for (long long i = 1; i <= m; i++){for (lon原创 2015-06-05 23:32:41 · 454 阅读 · 0 评论 -
UVA 11029 【快速幂】
Leading and Trailing Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %lluSubmit Status DescriptionYou are given two integers: n and k, your task is to find the most significant原创 2015-06-05 23:30:25 · 457 阅读 · 0 评论 -
LIGHTOJ 1005 – ROOKS
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1005代码://先在n行中选出k行,C(n,k),再在n列中选出k列随便放A(n,k),答案为C(n,k)*A(n,k)#include<stdio.h> #include<iostream> #include<math.h> #include<st原创 2015-06-05 23:26:08 · 792 阅读 · 0 评论 -
原根(最小)
#include <cstdio>#include <cstring>#include <queue>#include <iostream>#include <math.h>using namespace std;const int MAXN = 100000;int prime[MAXN+1];void getPrime(){ memset(prime,0,sizeof(prim原创 2015-06-05 18:17:47 · 1016 阅读 · 0 评论 -
POJ 1006 生理周期 【中国剩余定理】
生理周期 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 117999 Accepted: 37040 Description人生来就有三个生理周期,分别为体力、感情和智力周期,它们的周期长度为23天、28天和33天。每一个周期中有一天是高峰。在高峰这天,人会在相应的方面表现出色。例如,智力周期的高峰,人会思维敏捷,精力容易原创 2015-06-05 23:51:09 · 583 阅读 · 0 评论 -
UVA 11401 TRIANGLE COUNTING 【加法原理】
DescriptionProblem G Triangle CountingInput: Standard InputOutput: Standard OutputYou are given n rods of length 1, 2…, n. You have to pick any 3 of them & build a triangle. How many distinct triangle原创 2015-06-05 23:40:13 · 446 阅读 · 0 评论 -
LIGHTOJ 1007 – MATHEMATICALLY HARD【欧拉函数】
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1007题意:打表欧拉函数即可;代码:#include<stdio.h> #include<iostream> #include<math.h> #include<stdlib.h> #include<ctype.h> #include<alg原创 2015-06-05 23:24:13 · 431 阅读 · 0 评论 -
费马小定理
费马小定理: 一个素数是p 则对任意的整数a有a^p=a(mod p); 公式变形:a^(p-1)=1(mod p); 威尔逊定理: p为素数,则 (p-1)!=-1(mod p); 费马定理的应用:判断素数,大素数的生成; 若任意整数b有(b,n)==1,有b^(n-1)=1(mod n) n为素数; 否则,若b有(b,n)==1,有b^(n-1)!=1(mod n) n为合数。原创 2015-03-24 16:19:29 · 1038 阅读 · 0 评论 -
poj 1061 青蛙的约会 【扩展欧几里得】
青蛙的约会Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 93841 Accepted: 17330Description两只青蛙在网上相识了,它们聊得很开心,于是觉得很有必要见一面。它们很高兴地发现它们住在同一条纬度线上,于是它们约定各自朝西跳,直到原创 2015-03-10 18:26:19 · 654 阅读 · 0 评论 -
判断互质数的方法
一、概念判断法 公约数只有1的两个数叫做互质的数。根据互质数的概念。可以对一组数进行判断。如,4和9的公约数只有1,所以它们是互质数。 二、规律判断法 根据互质数的定义,可总结出一些规律,利用这些规律可迅速判断一组数是否互质。 (1)两个不相同的质数一定是互质数。例如,19和13是互质数。 (2)两个连续的自然数一定原创 2014-10-25 01:58:28 · 6540 阅读 · 0 评论 -
容斥原理
百度百科:在计数时,必须注意无一重复,无一遗漏。为了使重叠部分不被重复计算,人们研究出一种新的计数方法,这种方法的基本思想是:先不考虑重叠的情况,把包含于某内容中的所有对象的数目先计算出来,然后再把计数时重复计算的数目排斥出去,使得计算的结果既无遗漏又无重复,这种计数的方法称为容斥原理。两个集合的容斥关系公式:A∪B = A+B – A∩B (∩:重合的部分) 三个集合的容斥关系公式:A∪B∪C原创 2015-06-05 23:30:30 · 1065 阅读 · 0 评论 -
hau 3037 Saving Beans【Lucas定理】
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3037代码:#include <iostream>#include <cmath>#include <cstdio>using namespace std;long long pow(long long a, long long b, long long c){ long long tm原创 2016-01-14 16:26:23 · 342 阅读 · 0 评论 -
51nod 1135 原根
题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1135代码:#include <cstdio>#include <cstring>#include <queue>#include <iostream>#include <math.h>using namespace std;const int MAXN =原创 2015-10-03 02:06:11 · 399 阅读 · 0 评论 -
51nod 1181 质数中的质数(质数筛法)
题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1181代码:#include <stdio.h> #include <iostream> #include <string.h> #include <algorithm> #include <math.h> #include <stack>原创 2015-10-03 02:04:04 · 393 阅读 · 0 评论 -
51nod 1256 乘法逆元
题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1256水题求逆元。。代码:#include <stdio.h>#include <iostream>#include <string.h>#include <string>#include <cstring>#include <cmath>#includ原创 2015-10-03 01:31:26 · 351 阅读 · 0 评论 -
中国剩余定理
前面许多人讲过一些性质与证明,我来讲一讲解法,也是为了以后自己回过头来看。 中国剩余定理介绍 在《孙子算经》中有这样一个问题:“今有物不知其数,三三数之剩二(除以3余2),五五数之剩三(除以5余3),七七数之剩二(除以7余2),问物几何?”这个问题称为“孙子问题”,该问题的一般解法国际上称为“中国剩余定理”。具体解法分三步:找出三个数:从3和5的公倍数中找出被7除余1的最小数15,从3和7的公倍原创 2015-06-05 23:34:19 · 465 阅读 · 0 评论 -
逆元
数论中的逆元定义为: 设m是一个整数,a是满足(a,m)= 1 的整数,则存在唯一的整数a#,1<=a#<m, 使得 a *a# = 1( mod m); a#称为a的逆元; 求逆元的方法,可以用扩展欧几里得算法; sa+tm=(a,m)=1; 因此整数a#满足a# mod m=s满足a*a# = 1(mod m); 代码:long long ext_gcd(long long a,l原创 2015-06-05 23:32:21 · 501 阅读 · 2 评论 -
欧拉函数及其性质
对正整数n,欧拉函数是 例如euler(8)=4,因为1,3,5,7均和8互质。Euler函数表达通式:euler(x)=x(1-1/p1)(1-1/p2)(1-1/p3)(1-1/p4)…(1-1/pn),其中p1,p2……pn为x的所有素因数,x是不为0的整数。euler(1)=1(唯一和1互质的数就是1本身)。 欧拉公式的延伸:一个数的所有质因子之和是euler(n)*n/2原创 2015-03-11 16:27:43 · 1522 阅读 · 0 评论 -
当我真正理解素数线性筛法
参考自:点击链接 主要代码:const int MAXN = 10000010; bool com[MAXN]; int primes, prime[MAXN/10];//数组不必开的太大 void solve(int n) { primes = 0; memset(com,false,sizeof(com)); com[0] = com[1] =原创 2015-03-19 22:21:29 · 3174 阅读 · 0 评论 -
bzoj 2818 Gcd 【欧拉函数】
问题:求gcd(x,y)==质数, 1的有多少对?做这题的时候,懂得了一个非常重要的转化:求(x, y) = k, 1 的对数等于求(x, y) = 1, 1 的对数!所以,枚举每个质数p,然后求(x, y) = 1, 1 的个数。(x, y) = 1 的个数如何求呢?欧拉函数!#include #include #include #include #i原创 2015-03-11 17:34:01 · 721 阅读 · 0 评论 -
poj 1811 Prime Test【 随机素数测试与大数分解】
Prime Test Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 29925 Accepted: 7631 Case Time Limit: 4000MS DescriptionGiven a big integer number, you are required to find out wh原创 2015-03-24 16:41:39 · 821 阅读 · 0 评论 -
LightOJ 1341 - Aladdin and the Flying Carpet【合数分解】
题目链接:http://lightoj.com/volume_showproblem.php?problem=1341题意: 给出整数 a 和 b ,求区间[b, a] 内的 a 的约数对的个数,a 的约数对(比如[2, 3] 与 [3, 2] 为同一对)。解法: 主要利用公式: 一个整数n可以表示为若干素数乘积: n = p1^a1 * p2^a2*…*pm^am; 则 n 的正因数的个数原创 2015-06-17 17:15:23 · 1659 阅读 · 0 评论 -
poj 1006 生理周期 【中国剩余定理】
生理周期 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 117999 Accepted: 37040 Description人生来就有三个生理周期,分别为体力、感情和智力周期,它们的周期长度为23天、28天和33天。每一个周期中有一天是高峰。在高峰这天,人会在相应的方面表现出色。例如,智力周期的高峰,原创 2015-03-27 16:31:04 · 796 阅读 · 0 评论 -
我是好人 【欧几里得定理的性质】
Description 众所周知,我是好人!所以不会出太难的题,题意很简单 给你两个数n和m,问你有多少对正整数对最大公约数是n,最小公倍数是m最后友情提供解题代码(我真是太好人了)void solve(){long long n, m;scanf(“%lld%lld”, &n, &m);int ans = 0;for (long long i = 1; i <= m; i++){ for (l原创 2015-03-16 21:59:23 · 932 阅读 · 0 评论 -
hdu-1028 Ignatius and the Princess III 【母函数】
母函数:原创 2014-10-21 00:09:02 · 392 阅读 · 0 评论 -
hdu 4549 M斐波那契数列 【矩阵+快速幂+欧拉定理】
M斐波那契数列Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 1746 Accepted Submission(s): 503Problem Description M斐波那契数列F[n]是一种整数数列,它的定义如下:F[0] =原创 2015-03-25 23:48:37 · 607 阅读 · 0 评论 -
快速乘法计算模幂
一般的快速模幂可能会产生整数溢出的情况 ,可以用快速乘法解决此问题 。模板如下:#include #include #include #include #include using namespace std;long long mult_mod(long long a, long long b, long long c){ a %= c; b %= c; long原创 2015-03-15 21:01:40 · 611 阅读 · 0 评论 -
hdu-5104
时间卡的好死...首先将10000内的素数筛出来(约1000个),(p1,p2,p3)枚举三元组前两个p1,p2,可知若存在p3满足条件,必有p3=n−p1−p2,故令t=n−p1−p2。若t为不小于p2的素数,则t满足p3的条件。则答案加一。原创 2014-11-15 22:28:57 · 698 阅读 · 0 评论 -
hdu-1465 不容易系列之一 【排错公式】
问题提出:n封不同的信对应n个不同的信箱,问都装错信封的方法有多少种?分析:错排公式的递推式为: 不容易系列之一Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 15670 Accepted原创 2015-02-05 18:12:48 · 804 阅读 · 0 评论 -
快速幂算法的理解
首先给出代码:#include <iostream> using namespace std; //计算a^bmodn int modexp(int a,int b,int n) { int ret=1; int tmp=a; while(b) { if(b&1)原创 2015-03-20 16:24:08 · 2291 阅读 · 0 评论 -
逆元
数论中的逆元定义为: 设m是一个整数,a是满足(a,m)= 1 的整数,则存在唯一的整数a#,1<=a#<m, 使得 a *a# mod m=1; a#称为a的逆元; 求逆元的方法,可以用扩展欧几里得算法; sa+tm=(a,m)=1; 因此整数a#满足a# mod m=s满足a*a# mod m = 1;long long ext_gcd(long long a,long long原创 2015-03-20 16:49:58 · 2002 阅读 · 0 评论 -
poj 3070 Fibonacci 【矩阵快速幂】
Fibonacci Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10072 Accepted: 7191 DescriptionIn the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = Fn − 1 + Fn − 2 for n ≥ 2原创 2015-03-23 01:59:42 · 765 阅读 · 0 评论 -
当我真正理解了扩展欧几里得定理
首先、扩展欧几里得定理:对于两个不全为0的整数a、b,必存在一组解x,y,使得ax+by==gcd(a,b);void exgcd(long long a, long long b, long long & d, long long& x, long long& y){ if (!b) { d = a; x = 1; y = 0; //不明处1 } else {转载 2015-03-10 18:27:16 · 526 阅读 · 0 评论 -
light oj 1236 【大数分解】
给定一个大数,分解质因数,每个质因子的个数为e1,e2,e3,……em,则结果为((1+2*e1)*(1+2*e2)……(1+2*em)+1)/2.//light oj 1236 大数分解素因子#include #include #include #include #include #include #include #include #原创 2015-03-11 21:49:33 · 905 阅读 · 0 评论 -
Goldbach`s Conjecture 【素数线性筛法】
Goldbach`s ConjectureTime Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %lluSubmit StatusDescriptionGoldbach's conjecture is one of the oldest unsolved problems in n原创 2015-03-09 23:14:44 · 507 阅读 · 0 评论 -
BNU 13288 Bi-shoe and Phi-shoe 【素数筛选】
A - Bi-shoe and Phi-shoeTime Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %lluSubmit StatusDescriptionBamboo Pole-vault is a massively popular sport in Xz原创 2015-03-09 16:38:27 · 1020 阅读 · 0 评论 -
uva 11029 【快速幂】
Leading and TrailingTime Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %lluSubmit StatusDescriptionYou are given two integers: n and k, your task is to find the most原创 2015-03-09 18:48:35 · 495 阅读 · 0 评论 -
中国剩余定理
中国剩余定理介绍 在《孙子算经》中有这样一个问题:“今有物不知其数,三三数之剩二(除以3余2),五五数之剩三(除以5余3),七七数之剩二(除以7余2),问物几何?”这个问题称为“孙子问题”,该问题的一般解法国际上称为“中国剩余定理”。具体解法分三步:找出三个数:从3和5的公倍数中找出被7除余1的最小数15,从3和7的公倍数中找出被5除余1 的最小数21,最后从5和7的公倍数中找出除3余1原创 2015-03-27 16:42:03 · 641 阅读 · 0 评论 -
枚举全排列 STL next_permutation
#include#include#include#include#include#include#include#include#include#include#include#include#include#include#include#include#includeusing namespace std;int main (){ int n原创 2014-11-15 16:48:25 · 688 阅读 · 0 评论