当前位置:网站首页>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 .
边栏推荐
- 2021-03-09
- solidwork装配体导入到Adams中出现多个Part重名和Part丢失的情况处理
- Mapreduce实例(一):WordCount
- Samsung closes its last mobile phone factory in China
- Wechat applet personal number opens traffic master
- Mysql5.7 master-slave hot standby settings on CentOS
- MySQL index
- Simulation生成报表
- ARIMA model selection and residuals
- 4位数的随机数据
猜你喜欢

Mapreduce实例(二):求平均值

Excel提取重复项

Flume incrementally collects MySQL data to Kafka

The new JMeter function assistant is not under the options menu - in the toolbar

DRF learning notes (I): Data Serialization

Openwrt adds RTC (mcp7940 I2C bus) drive details

MapReduce instance (III): data De duplication

Keil implements compilation with makefile

Penetration test - dry goods | 80 + network security interview experience post (interview)

DRF learning notes (V): viewset
随机推荐
使用transform:translate()出现内容模糊问题
The new JMeter function assistant is not under the options menu - in the toolbar
profileapi.h header
mysql设置密码时报错 Your password does not satisfy the current policy requirements(修改·mysql密码策略设置简单密码)
Join hands with sifive, Galanz will enter the semiconductor field! Exposure of two self-developed chips
Solve mt7620 continuous cycle uboot (LZMA error 1 - must reset board to recover)
Leetcode 226 flip binary tree (recursive)
Rare bitwise operators
Sudden! 28 Chinese entities including Hikvision / Dahua / Shangtang / Kuangshi / ITU / iFLYTEK have been blacklisted by the United States
__ The difference between typeof and typeof
Have you ever used the comma operator?
const小结
解决flink启动后无法正常关闭
插入word中的图片保持高dpi方法
少见的按位操作符
4-digit random data
Taking advantage of 5g Dongfeng, does MediaTek want to fight the high-end market again?
C语言程序设计(第三版)
快速高效删除node_modules
DRF learning notes (II): Data deserialization