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; }