题解 | #阶乘#

阶乘

https://www.nowcoder.com/practice/e58c8a55162d49c48115bdfa5da7da56

#include <iostream>
using namespace std;

int main() {
    int a;
    while (cin >> a) { // 注意 while 处理多个 case
        int y1 = 0, y2 = 0;
        for (int i = 1, tmp = 1; i <= a; ++i) {
            tmp *= i;
            if (i % 2) y1 += tmp;
            else y2 += tmp;
        }
        cout << y1 << ' ' << y2 << endl;
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

07-11 10:56
门头沟学院 Java
码客明:大胆的说自己能实习6个月就行
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-08 14:08
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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