题解 | #阶乘#

阶乘

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

#include <iostream>
using namespace std;
int fac(int n){
    int res = 1;
    for(int i =1;i<=n;i++)res*=i;
    return res;
}
int main() {
    int n;
    while(cin>>n){
        int y1=0,y2=0;
        for(int i =1;i<=n;i+=2)
            y1+=fac(i);
        for(int i =2;i<=n;i+=2)
            y2+=fac(i);
        cout<<y1<<" "<<y2<<endl;
    }
}
// 64 位输出请用 printf("%lld")

原来暴力就能过啊。。。

全部评论

相关推荐

2025-12-18 22:04
已编辑
杭州电子科技大学 Java
程序员花海:技能放最后 另外这两个项目写的太简单了 没有业务没有技术栈 这种简历连HR都过不了
实习简历求拷打
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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