九度OJ 1179 阶乘(模拟)
#include<stdio.h> unsigned long long n; unsigned long long y1; unsigned long long y2; unsigned long long a[20]; void init(int n) { a[0]=1; a[1]=1; for(unsigned long long i=2;i<=n;++i) { a[i]=a[i-1]*i; } } unsigned long long gety1() { unsigned long long y1=0; for(int i=1;i<=n;i+=2) { y1+=a[i]; } return y1; } unsigned long long gety2() { unsigned long long y2=0; for(int i=2;i<=n;i+=2) y2+=a[i]; return y2; } int main(int argc, char *argv[]) { // freopen("1179.in", "r", stdin); while(~scanf("%llu",&n)) { init(n); printf("%llu %llu\n",gety1(),gety2()); } return 0; } /************************************************************** Problem: 1179 User: kirchhoff Language: C Result: Accepted Time:0 ms Memory:912 kb ****************************************************************/
版权声明:本文博客原创文章,博客,未经同意,不得转载。