3 3 4 5
1 1 2
一开始感觉像是递推关系,后来在网上看才知道是 母函数。是组合数学中的一个很有用的工具。
至于这道题可以说套模板 = =!
ACcode:
#include<cstdio> #include<cstring> #include<cmath> #define mem(a, b) memset(a, (b), sizeof(a)) #define Wi(a) while(a--) #define Si(a) scanf("%d", &a) #define Pi(a) printf("%d\n", (a)) int c1[155],c2[155],pr[100],a[300]; int d = 0; void isprime(){ int i, j; for(i = 2; i <= 150; i++) for(j = i*2; j <= 150; j+=i) a[j] = 1; for(i = 2; i <= 150; i++) if(a[i] == 0) pr[++d] = i; } int main(){ int t, n; isprime(); mem(c1, 0); mem(c2, 0); int i, j, k; Si(t); for(i = 0; i <= 150; i+=2) c1[i] = 1; for(i = 2; i <= d; i++) { for(j = 0; j <= 150; j++) for(k = 0; k<=150 && k+j <= 150; k+=pr[i]) c2[j+k] += c1[j]; for(j = 0; j <= 150; j++) { c1[j] = c2[j]; c2[j] = 0; } } Wi(t) { Si(n); Pi(c1[n]); } return 0; }