牛牛学数列3
牛牛学数列3
https://ac.nowcoder.com/acm/problem/22158
先计算有规律变化的分母
#include<cstdio> #include<cmath> int count(int n); int main(){ int n; scanf("%d", &n); double sum = 0; for(int i = 1; i <= n; i++){ double temp = 1.0 / count(i); sum += temp; } printf("%.3f", sum); return 0; } int count(int n){ int temp = 0; for(int i = 1; i <= n; i++){ temp += pow(-1, i-1) * (2*i-1) * 1.0; } return temp; }