蛙声一片

P1009 [NOIP1998 普及组] 阶乘之和

dingding2008 @ 2023-05-13 22:07:44

#include <bits/stdc++.h>
using namespace std;
const int N = 5010;
int a[N], b[N];
int len = 1, len2 = 1;
inline void add()
{

}
inline int mul(int x[], int y)
{
  for (int i = 1; i <= len; i++)
  {
    x[i] *= y;
  }
  for (int i = 1; i < len; i++)
  {
    x[i+1] += x[i] / 10;
    x[i] %= 10;
  }
  while (x[len] >= 10)
  {
    x[len+1] += x[len] / 10;
    x[len] %= 10;
    len++;
  }
  return len;
}
int main()
{
  int n;
  scanf("%d", &n);
  b[1] = 1;
  for (int i = 1; i <= n; i++)
  {
    mul(b, i);
    add();
  }
  for (int i = len2; i >= 1; i--)
  {
    printf("%d", a[i]);
  }
  return 0;
}

dalao们,谁能告诉我add函数怎么写啊... 如果帮我AC了,我就可以关注你. 本萌新太垃圾了(我才四年级)


by X_Sbr @ 2023-10-21 12:50:41

@2011Andy 还有另一种易理解的

def jih(a):
    si=0
    for i in range(1,a+1):
        sj=1
        for j in range(2,i+1):
            sj=sj*j
        si+=sj
    return(si)
n=int(input())
print(jih(n))

by 2011Andy @ 2023-10-22 08:36:45

@X_zhin 666,五月的帖子你还看


上一页 |