時間限制: 1 sec 記憶體限制: 128 mb
求組合數c(n,m),以及c(n,m)因子個數。
n和m,其中0<=m<=n<=50,以eof結束。
該組合數結果。
3 24 2
3 2先利用楊輝三角求出組合數,然後就是求出因子數了;6 4
求因子數:素數分解的唯一性,乙個數可以被分解成若干素數相乘 p1^x1*p2^x2*...*pn^xn;
根據乘法原理,因子數為(x1+1)*(x2+1)*...*(xn+1);
c(n,m)=n!/m!/(n-m)!,直接將所有階乘的數分解出所有素因數然後統計一下,然後套用上面的公式就好;
令dp[i][j]代表為i的階乘中j因子的個數(j是素數),那麼i素數的個數為dp[n][i]-dp[m][i]-dp[n-m][i];
最後for迴圈從1到n列舉i統計。
#include #include #include long long a[60][60];
const int maxn = 60;
int vis[maxn], dp[maxn][maxn];
void c()
void sieve(int n)
int get(int n, int m)
return sum;
}void pre(int n)
int mm(int n, int m)
int main()
組合數學 求組合數
對於求組合數,要根據所給資料範圍來選擇合適的演算法 這道題中所給的資料範圍適合用打表的方法直接暴力求解 先用4e6的複雜度預處理出所有的情況,再用1e4的複雜度完成詢問即可 include using namespace std const int n 2010 const int mod 1e9 ...
N 求組合數!
給出兩個數 n,m。求 計算公式 input 輸入資料有多組 資料組數不超過 250 到 eof 結束。對於每組資料,輸入兩個用空格隔開的整數 n,m 0 m n 20 output 對於每組資料輸出一行,example input 1 1 20 1 20 10 example output 1 1...
1131 求組合數
1131 求組合數 description 組合數cnr n,r n r n r 雖然組合數的計算簡單但也不乏有些陷阱,這主要是因為語言中的資料型別在表示範圍上是有限的。更何況還有中間結果溢位的現象,所以千萬要小心。input 求組合數的資料都是成對 m與n 出現的,你可以假設結果不會超過64位有符...