摘要: 由于素数P比较小,所以可以先打表,求出小于P的数的阶乘对与该素数的余数,这样节省了中间求阶乘的时间。/* * soj3290.c * * Created on: 2011-10-10 * Author: bjfuwangzhu */#include<stdio.h>#define LL long long#define nmod 10009int num[nmod];void init() { int i; for (i = 1, num[0] = 1; i < nmod; i++) { num[i] = num[i - 1] * i % nmod; ... 阅读全文
posted @ 2011-10-10 13:06 qingyezhu 阅读(205) 评论(0) 推荐(0)
摘要: 1)根据一下公式,直接计算 C(n,m) mod p = n*``*(n-m+1)/(1*``*m) mod p 计算分别分子nn、分母mm中p的个数和对p的余数,若分子中p的个数多余分母中p的个数,则结果为0, 若不是,则原式变为nn/mm mod p (nn,p)=1,(mm,p)=1 此时如何求逆元变得至关重要,以下有两种解法。2)Lucas 定理:是用来求 C(n,m) mod p的值,p是素数。 描述为: Lucas(n,m,p)=C(n%p,m%p)* Lucas(n/p,m/p,p) Lucas(n,0,p)=1; 而 C(a,b)=a*(a-1)*```*(a-... 阅读全文
posted @ 2011-10-10 12:03 qingyezhu 阅读(1061) 评论(0) 推荐(0)
摘要: 对于本题的因数m,只需要将其化素因子的乘积形式,之后只需要判定每一个素因子p在组合数中的个数是否大于或等于在因数m中的个数,若是则输出Yes,若存在某一个不是则输出No。至于如何判断一个素因子在组合数中的个数,如下所示://获得素因子p在1*2*··n中的个数int getNum(int n, int p) { int res; res = 0; while (n) { res += n / p; n /= p; } return res;}代码如下:#include<stdio.h>#include<string.h>#include... 阅读全文
posted @ 2011-10-10 10:38 qingyezhu 阅读(252) 评论(0) 推荐(0)
摘要: 对于本题的因数m,只需要将其化为素因子的乘积形式,其中每一个素因子的个数为mi,之后只需要求得每一个素因子pi在组合数中的个数Ci,然后将取Ci/mi中的最小的那个,就是该因数在组合数中的个数。代码如下:/* * fafu1079.c * * Created on: 2011-10-9 * Author: bjfuwangzhu */#include<stdio.h>#include<string.h>#include<math.h>#define nmax 31625int flag[nmax], prime[nmax], pfactor[nmax], c 阅读全文
posted @ 2011-10-09 21:24 qingyezhu 阅读(295) 评论(0) 推荐(0)
摘要: /* * hdu2199.c * * Created on: 2011-10-9 * Author: bjfuwangzhu */#include<stdio.h>#include<math.h>#define eps 1.0e-10double f(double x) { return 8.0 * pow(x, 4.0) + 7.0 * pow(x, 3.0) + 2.0 * pow(x, 2.0) + 3 * x + 6;}void solve(double y) { double left, right, mid; left = 0.0, right = 1... 阅读全文
posted @ 2011-10-09 19:56 qingyezhu 阅读(168) 评论(0) 推荐(0)
摘要: /* * hdu2141.c * * Created on: 2011-10-9 * Author: bjfuwangzhu */#include<stdio.h>#include<stdlib.h>#define nmax 5001#define nnum 250001#define LL long longLL numL[nmax], numN[nmax], numM[nmax], numLN[nnum];int cmp(const void *a, const void *b) { LL temp = *(LL *) a - *(LL *) b; if (temp 阅读全文
posted @ 2011-10-09 19:55 qingyezhu 阅读(213) 评论(0) 推荐(0)
摘要: /* * hdu1969.c * * Created on: 2011-10-9 * Author: bjfuwangzhu */#include<stdio.h>#include<stdlib.h>#include<math.h>#define nmax 10010#define pi acos(-1.0)#define eps 1.0e-5double volume[nmax];int cmp(int n, double aver) { int i, temp; for (i = 0, temp = 0; i < n; i++) { temp += 阅读全文
posted @ 2011-10-09 19:53 qingyezhu 阅读(166) 评论(0) 推荐(0)
摘要: /* * hdu1511.c * * Created on: 2011-10-9 * Author: bjfuwangzhu */#include<stdio.h>#include<math.h>#define eps 1.0e-8#define nmax 10001double num[nmax];int cmp(int n, double aver) { int i, temp; for (i = 0, temp = 0; i < n; i++) { temp += (int) (num[i] / aver); } return temp;... 阅读全文
posted @ 2011-10-09 19:52 qingyezhu 阅读(363) 评论(0) 推荐(0)
摘要: /* * hdu2899.c * * Created on: 2011-10-9 * Author: bjfuwangzhu */#include<stdio.h>#include<math.h>#define eps 1.0e-8double ff(double x, double y) { return 42.0 * pow(x, 6.0) + 48.0 * pow(x, 5.0) + 21.0 * pow(x, 2.0) + 10.0 * x - y;}double f(double x, double y) { return 6.0 * p... 阅读全文
posted @ 2011-10-09 14:27 qingyezhu 阅读(166) 评论(0) 推荐(0)
摘要: #include<stdio.h>#include<numeric>#include<iostream>#include<functional>#include<algorithm>#include<vector>using namespace std;#define LL long long#define nmax 20int num[nmax];struct node { int x;};struct Add { int operator()(int n, node &M) const { return n + 阅读全文
posted @ 2011-10-06 21:50 qingyezhu 阅读(166) 评论(0) 推荐(0)