当前位置:网站首页>Addition of large numbers
Addition of large numbers
2022-07-27 16:23:00 【Xavier】
Algorithm is summarized : Add large numbers
We will inevitably encounter large numbers in the process of calculation , And a variable cannot be stored , So we need to use the linear table to calculate .
We can pass an example
1!+2!+3!+4!+…50!
int n,a[1000]={
0},b[1000]={
0}; // Initialize the array to zero
scanf("%d",&n);
a[0]=b[0]=1; // Take the first element as 1 Convenient for later multiplication
for(int i=2;i<=n;i++){
for(int j=0;j<100;j++)
a[j]*=i;
// stay a Calculate the factorial of each number in this array
for(int j=0;j<100;j++)
if(a[j]>9){
a[j+1]+=a[j]/10;
a[j]%=10;
}
This part is the result of calculating the factorial number of each part
for(int j=0;j<100;j++){
b[j]+=a[j];
if(b[j]>9){
b[j+1]+=b[j]/10;
b[j]%=10;
}
}
This section is to calculate the sum of each factorial result
Therefore, through the array, you can calculate large numbers so that there will be no data overflow in a single variable .
边栏推荐
- TSMC's 6-nanometer manufacturing process will enter trial production in the first quarter of next year
- word中插入度的方法
- Chuanyin holdings disclosed that it was prosecuted by Huawei: a case has been filed, involving an amount of 20million yuan
- TSMC's counterattack: it accused lattice core of infringing 25 patents and asked for prohibition!
- Axure 安装图标字体元件库
- Web test learning notes 01
- Embedded development: tips and techniques -- seven techniques to meet the real-time deadline
- const小结
- Personal perception of project optimization
- flink打包程序提交任务示例
猜你喜欢

Solve the problem that Flink cannot be closed normally after startup

Excel提取重复项

Solve mt7620 continuous cycle uboot (LZMA error 1 - must reset board to recover)

Openwrt adds support for SD card

mysql设置密码时报错 Your password does not satisfy the current policy requirements(修改·mysql密码策略设置简单密码)

flume增量采集mysql数据到kafka

2.2 JMeter基本元件

Yys mouse connector

DRF learning notes (I): Data Serialization

企业运维安全就用行云管家堡垒机!
随机推荐
4位数的随机数据
Pycharm导入已有的本地安装包
解决flink启动后无法正常关闭
少见的按位操作符
Introduction to JWT
The 4.3 billion euro cash acquisition of OSRAM failed! AMS said it would continue to acquire
TSMC's 6-nanometer manufacturing process will enter trial production in the first quarter of next year
Sudden! 28 Chinese entities including Hikvision / Dahua / Shangtang / Kuangshi / ITU / iFLYTEK have been blacklisted by the United States
Test novice learning classic (with ideas)
Rare bitwise operators
Taking advantage of 5g Dongfeng, does MediaTek want to fight the high-end market again?
Chuanyin holdings disclosed that it was prosecuted by Huawei: a case has been filed, involving an amount of 20million yuan
Install MySQL using CentOS yum
Boolean value
Personal perception of project optimization
Mysql5.7 master-slave hot standby settings on CentOS
Coturn service installation in webrtc
Oracle 常用语句
C language programming (Third Edition)
These questions~~