1到50列表,阶乘之和
S=1!+2!+3!+⋯+n!(n≤50)
1::1
2::3
3::9
4::33
5::153
6::873
7::5913
8::46233
9::409113
10::4037913
11::43954713
12::522956313
13::6749977113
14::93928268313
15::1401602636313
16::22324392524313
17::378011820620313
18::6780385526348313
19::128425485935180313
20::2561327494111820313
21::53652269665821260313
22::1177652997443428940313
23::27029669736328405580313
24::647478071469567844940313
25::16158688114800553828940313
26::419450149241406189412940313
27::11308319599659758350180940313
28::316196664211373618851684940313
29::9157958657951075573395300940313
30::274410818470142134209703780940313
31::8497249472648064951935266660940313
32::271628086406341595119153278820940313
33::8954945705218228090637347680100940313
34::304187744744822368938255957323620940313
35::10637335711130967298604907294846820940313
36::382630662501032184766604355445682020940313
37::14146383753727377231082583937026584420940313
38::537169001220328488991089808037100875620940313
39::20935051082417771847631371547939998232420940313
40::836850334330315506193242641144055892504420940313
41::34289376947494122614363304694584807557656420940313
42::1439295494700374021157505910939096377494040420940313
43::61854558558074209658512637979453093884758552420940313
44::2720126133346522977702138448994068984204397080420940313
45::122342346998826717539665299944651784048588130840420940313
46::5624964506810915667389970728744906677010239883800420940313
47::264248206017979096310354325882356886646207872272920420940313
48::12678163798554051767172643373255731925167694226950680420940313
49::620960027832821612639424806694551108812720525606160920420940313
50::31035053229546199656252032972759319953190362094566672920420940313
题:洛谷:P1009 [NOIP1998 普及组] 阶乘之和
代码
#include <stdio.h>
int main(void) {
int n, sum[70] = { 0 }, sin[70] = { 0 };
sin[0] = 1;
scanf_s("%d", &n);
for (int i = 1; i <= n; i++) {
sin[0] = 1;
for (int k = 1; k <= i; k++) {//计算每个阶乘
for (int j = 0; j < 70; j++) {
sin[j] *= k;
}
for (int j = 0; j < 70 - 1; j++) {
if (sin[j] > 9) {
sin[j + 1] += sin[j] / 10;
sin[j] %= 10;
}
}
}
for (int j = 0; j < 70; j++) {//每个阶乘与sum相加
sum[j] += sin[j];
sin[j] = 0;
}
for (int j = 0; j < 70; j++) {
if (sum[j] > 9) {
sum[j + 1] += sum[j] / 10;
sum[j] %= 10;
}
}
}
for (int i = 69; i >= 0; i--) {//输出
if (sum[i] != 0) {
for (int j = i; j >= 0; j--) {
printf("%d", sum[j]);
}
break;
}
}
}
标签:10,洛谷,P1009,int,sum,50,阶乘,sin
From: https://www.cnblogs.com/l25428455/p/17766760.html