当前位置:网站首页>Somme factorielle
Somme factorielle
2022-06-21 14:46:00 【Utilisateurs 6978604】
Source du sujet:CRéseau linguistique1014
Description du problème
S'il te plaît.Sn=1!+2!+3!+4!+5!+…+n!Valeur,Parmi euxnC'est un nombre(nPas plus de20).
Exemple d'entrée
5Exemple de sortie
153Résolution de problèmes
/*
* @Author: YaleXin
* @Date: 2020-05-22 20:40:31
* @LastEditTime: 2020-05-22 22:19:56
* @LastEditors: YaleXin
* @Description:
* @FilePath: \my_c_workspace\dotcpp\1014.c
* @La prière ne vient pasBUG
*/
#include <stdio.h>
#define MAX_NUM 100
typedef struct factorial {
int factorial[100];
} f;
f num[25];
int ans[100] = {0};
// Stockage de haute précision
void setNum(int index) {
if (index == 1) {
num[1].factorial[1] = 1;
return;
} else {
int c = 0, mul = 0, i;
for (i = 1;; i++) {
mul = (num[index - 1].factorial[i] * index + c) % MAX_NUM;
c = (num[index - 1].factorial[i] * index + c) / MAX_NUM;
num[index].factorial[i] = mul;
if ((mul + c + num[index - 1].factorial[i + 1]) == 0) break;
}
}
}
int addAns(int index) {
int c = 0, i, sum = 0;
for (i = 1;; i++) {
sum = (ans[i] + num[index].factorial[i] + c) % MAX_NUM;
c = (ans[i] + num[index].factorial[i] + c) / MAX_NUM;
ans[i] = sum;
if ((sum + c + ans[i + 1]) == 0) break;
}
return i;
}
int main() {
int n, i, len;
scanf("%d", &n);
for (i = 1; i <= n; i++) {
setNum(i);
len = addAns(i);
}
for (i = len - 1; i >= 1; i--) {
// Premier zéro avant enlevé
if (ans[i] < 10 && i != len - 1) {
printf("0%d", ans[i]);
} else {
// Zéro à un chiffre
printf("%d", ans[i]);
}
}
return 0;
}边栏推荐
- T32 add toolbar button
- SSH based command operation
- ARP interaction process
- Record the troubleshooting process of excessive CPU usage
- First Canary deployment with rancher
- Summary of common libraries in machine learning
- Numpy: basic package for high performance scientific computing & data analysis
- Subshell
- ‘maxflow‘ has no attribute ‘Graph‘
- Windows系统下C语言连接MySQL
猜你喜欢

Word thesis typesetting tutorial
![[how to install MySQL 8.0 to a non system disk] [how to create a new connection with Navicat and save it to a non system disk] and [uninstall MySQL 8.0]](/img/e4/895cc829e34692a069923e226deb11.jpg)
[how to install MySQL 8.0 to a non system disk] [how to create a new connection with Navicat and save it to a non system disk] and [uninstall MySQL 8.0]

Win10 install tensorflow

Gensim error attributeerror: type object 'word2vec' has no attribute 'load_ word2vec_ format‘

Tcp/ip FAQs

Read distributed consistency protocols 2pc and 3pc

Subshell

Decipher Bishengyuan: is it tea that consumers buy, or is it IQ tax?

Qt-6-file IO

HSV color model and color component range in opencv
随机推荐
Dplayer development barrage background
[untitled] fish pond forwarding command
Select article (040) - what is the log output when you click this paragraph?
Continuous attack animation
Pyqt5 learning notes of orange_ Connect to SQL Server database
For the first time in China, Tsinghua and other teams won the wsdm2022 only best paper award, and Hong Kong Chinese won the "time test Award"
Reptile Foundation_ Requests Library
Invisible characters encountered \u200b
Kubeneters installation problems Collection
Summary of web development technology knowledge
Qt-4-common classes and components
Chapter 3 - data link layer
Win10 install tensorflow
Win10 installation and configuration mongodb
网上开户安全吗?新手可以开账户吗
Promotion guide for large enterprises: material preparation, PPT writing and on-site defense
HSV color model and color component range in opencv
Reverse generate the corresponding DTD constraint according to the XML file
Windows系统下C语言连接MySQL
2022 Hunan latest fire facility operator simulation test question bank and answers