/* -*- coding: utf-8 -*- * * 731.cc: No.731 等差数列がだいすき - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 1000; /* typedef */ /* global variables */ double ys[MAX_N]; /* subroutines */ /* main */ int main() { int n; scanf("%d", &n); double xsum = 0.0, x2sum = 0.0, xysum = 0.0, ysum = 0.0; for (int i = 0; i < n; i++) { scanf("%lf", &ys[i]); xsum += i; x2sum += i * i; xysum += i * ys[i]; ysum += ys[i]; } double e = n * x2sum - xsum * xsum; double d = (n * xysum - xsum * ysum) / e; double b = (x2sum * ysum - xysum * xsum) / e; double ddsum = 0.0; for (int i = 0; i < n; i++) { double dy = (b + d * i) - ys[i]; ddsum += dy * dy; } printf("%.14lf %.14lf\n%.14lf\n", b, d, ddsum); return 0; }