牛牛学数列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;

}
全部评论

相关推荐

头顶尖尖的程序员:我也是面了三四次才放平心态的。准备好自我介绍,不一定要背熟,可以记事本写下来读。全程控制语速,所有问题都先思考几秒,不要急着答,不要打断面试官说话。
点赞 评论 收藏
分享
每晚夜里独自颤抖:这个在牛客不是老熟人了吗
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务