随笔分类 - 数学题
HDU2519组合数快速算法
摘要:#define DeBUG#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std ;#define zero {0}#define INF 2000000000#define EPS 1e-6typedef long long LL;const double PI = acos(-1.0);inline int s...
阅读全文
分解质因数与约数和
摘要:1.有多少个约数: 先分解质因数 因数的次数分别是4,2,1 所以约数的个数为(4+1) *(2+1) *(1+1)=5*3*2=30 个 eg: 先分解质因数 720=2^4*3^2*5 因数的次数分别是4,2,1 所以约数的个数为(4+1)*(2+1)*(1+1)=5*3*2=30 个2.所有约数之和:2004 的约数之和为:1, 2, 3, 4, 6, 12, 167, 334, 501, 668, 1002 ,2004 = 4704如何求一个数所有约数之和呢?首先,应用算术基本定理,化简为素数方幂的乘积。X = a1^k1 * a2^k2........an^kn X 的所有素数之和.
阅读全文
HDU4497GCD and LCM
摘要:GCD and LCMTime Limit: 2000/1000 MS (Java/Others)Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 50Accepted Submission(s): 27Problem DescriptionGiven two positive integers G and L, could you tell me how many solutions of (x, y, z) there are, satisfying that gcd(x, y, z) = G and lcm(x,
阅读全文
取模问题
摘要:很多地方用到模运算,这里说明模运算的一些规律,并加以证明。 后续会对这些理论实际的应用加以记录和说明。1. 模运算是取余运算(记做 % 或者 mod),具有周期性的特点。 m%n的意思是n除m后的余数,当m递增时m%n呈现周期性特点,并且n越大,周期越长,周期等于n。 例如 0 % 20 = 0,1 % 20 = 1, 2 % 20 = 2, 3 % 20 = 3, ..., 19 % 20 =19 20 % 20 = 0,21 % 20 = 1,22 % 20 = 2,23 % 20 = 3, ...,39 % 20 =192. 如果 m % n = r,那么可以推出如下等式 m =...
阅读全文
ACM南京邀请赛Yet another end of the world数学题
摘要:Yet another end of the worldTime Limit: 6000/3000 MS (Java/Others)Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 0Accepted Submission(s): 0 Problem DescriptionIn the year 3013, it has been 1000 years since the previous predicted rapture. However, the Maya will not play a joke any mor
阅读全文
HDU4608 Magic Pen 6
摘要:Magic Pen 6Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 840Accepted Submission(s): 304 Problem DescriptionIn HIT, many people have a magic pen. Lilu0355 has a magic pen, darkgt has a magic pen, discover has a magic pen. Recently, Timer also got
阅读全文
HDU1212加深下对取模运算的理解
摘要:Big NumberTime Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3771Accepted Submission(s): 2586 Problem DescriptionAs we know, Big Number is always troublesome. But it's really important in our ACM. And today, your task is to write a program to cal
阅读全文
HDU1410概率的对数优化
摘要:出处http://www.clanfei.com/2012/04/772.html 1 #include 2 #include 3 int main() 4 { 5 int HP1,HP2,AP1,AP2,N1,N2 ; 6 while(scanf("%d%d%d%d",&HP1,&HP2,&AP1,&AP2)!=EOF) 7 { 8 double ans=0,tmp=0 ; 9 N1=(HP2-1)/AP1+1 ;10 N2=(HP1-1)/AP2+1 ;11 ans=pow(0.5,N1);12 ...
阅读全文
数学公式集锦
摘要:1错排公式HDU1465a[1]=0;a[2]=1;a[i]=(i-1)*(a[i-1]+a[i-2]);2----求卡特兰数令h(0)=1,h(1)=1,catalan数满足递推式[1]:h(n)= h(0)*h(n-1)+h(1)*h(n-2) + ... + h(n-1)h(0) (n>=2)例如:h(2)=h(0)*h(1)+h(1)*h(0)=1*1+1*1=2h(3)=h(0)*h(2)+h(1)*h(1)+h(2)*h(0)=1*2+1*1+2*1=5另类递推式[2]:h(n)=h(n-1)*(4*n-2)/(n+1);递推关系的解为:h(n)=C(2n,n)/(n+1)
阅读全文
HDU1292 i个不同元素分成j堆的分法
摘要:1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 10 #include11 #include12 using namespace std ;13 #ifdef DeBUG14 #define bug assert15 #else16 #define bug //17 #endif18 19 int main()20 {21 #ifdef DeBUG22 freopen("C:\\Users\\Sky\\D...
阅读全文
快速幂,就当个模板了
摘要:1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 10 #include11 #include12 using namespace std ;13 #ifdef DeBUG14 #define bug assert15 #else16 #define bug //17 #endif18 int pow3(int a, int b)19 {20 int r = 1, base = a;21 while(b != 0)...
阅读全文