POJ-2292(求约数个数)(Divisors)

来源:互联网 发布:android建服务器软件 编辑:程序博客网 时间:2024/05/02 01:36

【题目描述】

Your task in this problem is to determine the number of divisors of C(n,k).

【解题思路】

1.约数个数定理:设n的标准质因数分解为n=p1^a1*p2^a2*...*pm^am,则n的因数个数=(a1+1)*(a2+1)*...*(am+1).
2.n!的素因子 = (n-1)!的素因子 + n的素因子
3.c(n,k)的素因子分解 = n!的素因子- (n-k)!的素因子 - k!的素因子

bool prime(int n)

{int i, limit;if (n <= 1) return false;if (n == 2) return true;if (n % 2 == 0) return false;limit = sqrt(n * 1.0) + 1;//计算机计算的平方根可能会是.999999,这样就不会去判断是否被整除,会被误判for (i = 3; i <= limit; ++i) if (n % i == 0) return false;return true;}int ans[500][88];int main(){int i, j;int d[500];int index = 0;for (i = 1; i <= 431; ++i) {if (prime(i)) {d[index++] = i;}}for (i = 2; i <= 431; ++ i) {int t = i;for (j = 0; j < 83; ++j) {if (t < d[j])break;int sum = 0;while (t % d[j] == 0) {ans[i][j]++;t /= d[j];if (t == 1)break;}}}for (i = 3; i <= 431; ++ i) {for (j = 0; j < 83; ++j) {ans[i][j] += ans[i - 1][j];}}int a, b;while (scanf("%d%d", &b, &a) == 2) {ll x = 1;for (i = 0; i < index; ++i) {x *= (ans[b][i] - ans[a][i] - ans[b - a][i] + 1);}printf("%lld\n", x);}return 0;}


原创粉丝点击