#include #include typedef double R; typedef struct{R c; R m;} S; R Pow(R x, int k) {R t=1; while(k--) t=t*x; return t;}; S c(int n, R * a) { S r(R b, int j) { if(b<0) return (S){0, 0}; if(j<0) {R t = Pow(b, n); return (S){t, b*t};} {S r0 = r(b, j-1), r1 = r(b - a[j], j-1); return (S){r0.c-r1.c, r0.m-r1.m};}} {int j=n; R p=1, b=0; while(j--) {p=p*a[j]*(j+1); b += a[j]*a[j];}; {S s = r(1, n-1); return (S){s.c/p, s.m/(sqrt(b)*p*(n+1))};}}} int main(){ R w[] = {2, 2}; {S s = c(sizeof(w)/sizeof(w[0]), w); printf("c=%15.12f, m=%15.12f\n", s.c, s.m);} return 0;}