POJ 2992 divisors to find the number of combinatorial factors

Source: Internet
Author: User

Title Source: POJ 2992 divisors

Test instructions: ...

Idea: The uniqueness of prime decomposition a number can be decomposed into several prime numbers multiplied P1^X1*P2^X2*...*PN^XN

Number of factors according to multiplication principle (x1+1) * (x2+1) *...* (xn+1)

Can not directly find the combination of the number of overflow can not be multiplied by the number of decomposition factor so that will time out

C (n,m) =n!/(m!* (n-m)!)

Another dp[i][j] represents the number of j factors in the factorial of I (J is prime)

Then the number of I primes is dp[n][i]-dp[m][i]-dp[n-m][i]

Last for loop from 1 to N enumeration I statistics

#include <cstdio> #include <cstring> #include <cmath> using namespace std;
const int MAXN = 500;
int VIS[MAXN];
int PRIME[MAXN];
int DP[MAXN][MAXN];
	Sieve primes void sieve (int n) {int m = sqrt (n+0.5);
	memset (Vis, 0, sizeof (VIS));
	Vis[0] = vis[1] = 1;
for (int i = 2, I <= m; i++) if (!vis[i]) for (int j = i*i; J <= N; j + = i) vis[j] = 1;
	} int Get_primes (int n) {sieve (n);
	int c = 0;
	for (int i = 2; I <= n; i++) if (!vis[i]) prime[c++] = i;
return C;
	} int get (int n, int m) {int sum = 0;
		while (n) {sum + = n/m;
	n/= m;
} return sum;
	} void pre (int n) {for (int i = 2; I <= n; i++) {for (int j = 2; J <= I; j + +) Dp[i][j] = Get (i, j);
	}} int main () {int c = get_primes (444);
	Pre (444);
	int n, m;
		while (scanf ("%d%d", &n, &m)! = EOF) {Long long ans = 1;
			for (int i = 2; I <= n; i++) {if (vis[i]) continue;
			C (n,m) =n!/(m!* (n-m)!)
		Ans *= dp[n][i]-dp[m][i]-dp[n-m][i] + 1; } printf ("%lld\n", ans);
} return 0; }


 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.