当前位置:网站首页>P1009 [noip1998 popularization group] sum of factorials
P1009 [noip1998 popularization group] sum of factorials
2022-07-29 04:54:00 【Chen Yuchen】
Title Description
Calculate with high precision S = 1! + 2! + 3! +⋯+ n!S=1!+2!+3!+⋯+n!(n \le 50n≤50).
among “!” It means factorial , for example :5!=5×4×3×2×1.
Input format
A positive integer nn.
Output format
A positive integer SS, It means the result of calculation .
I/o sample
Input #1 Copy
3
Output #1 Copy
9
explain / Tips
【 Data range 】
about 100% The data of ,1≤n≤50.
Be careful : General data types can only be saved n<=20 The data and , So here we use java Of BigInteger Class to calculate , Need to use BigInteger Class multiply Methods and add Method !!!
import java.util.*;
import java.math.*;
public class Main{
public static void main(String[]args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
BigInteger bi[] = new BigInteger[n+1];// Why? n+1, For better understanding and initialization . Define a n+1 BigInteger Array of classes
BigInteger biSum = new BigInteger("0");// Class instances for summation
for(int i = 1;i <= n;i++){
bi[i] = new BigInteger(String.valueOf(i));// Initialize class array .
}
for(int i = 1;i <= n;i++){
BigInteger temp = new BigInteger("1");// Temporary variable , Used to receive 1~n Factorial of each digit of
for(int j = 1 ;j <=i;j++){
temp = temp.multiply(bi[j]);
}
biSum = biSum.add(temp);// Used to sum and save 1~n Sum of factorials of various numbers
}
System.out.println(biSum);
}
}
边栏推荐
- How to set row height and column width in excel? The method of setting row height and column width in Excel
- Leetcode 763. partition labels divide alphabetic intervals (medium)
- 带你搞懂 Kubernetes 集群中几种常见的流量暴露方案
- Flink+Iceberg环境搭建及生产问题处理
- Double type nullpointexception in Flink flow calculation
- 虚拟偶像的歌声原来是这样生成的!
- After the spinning up installation is completed, use the tutorial to test whether it is successful. There are library "Glu" not found and 'from pyglet.gl import * error solutions
- office2010每次打开都要配置进度怎么解决?
- Classes and objects (I)
- Learn matlab to draw geographical map, line scatter bubble density map
猜你喜欢

ssm整合增删改查

Implementation of img responsive pictures (including the usage of srcset attribute and sizes attribute, and detailed explanation of device pixel ratio)
![学术 | [LaTex]超详细Texlive2022+Tex Studio下载安装配置](/img/4d/f8c60c0fbbd98c4da198cfac7989fa.png)
学术 | [LaTex]超详细Texlive2022+Tex Studio下载安装配置

Use more flexible and convenient Rogowski coil

Review key points and data sorting of information metrology in the second semester of 2022 (teacher zhaorongying of Wuhan University)

Ethernet of network

File operation (Advanced C language)

spinning up安装完使用教程测试是否成功,出现Library“GLU“ not found和‘from pyglet.gl import *错误解决办法

Learn matlab to draw geographical map, line scatter bubble density map

IDEA中使用注解Test
随机推荐
un7.28:redis客户端常用命令。
How to debug UDP port
Mysql各版本下载地址及多版本共存安装
手机工作室网络如何组建?
C language implementation of three chess
EMI interference troubleshooting with near-field probe and current probe
怎样监测微型的网站服务
Introduction to auto.js script development
数据湖:分布式开源处理引擎Spark
Basic grammar of C language
IOS interview preparation - other articles
Leetcode 763. partition labels divide alphabetic intervals (medium)
RecyclerView通过DPAD按键上下切换焦点 切换到界面外的控件时焦点会左右乱跳
Big silent event Google browser has no title
虚拟偶像的歌声原来是这样生成的!
DataSourceClosedException: dataSource already closed at Mon Oct 25 16:55:48 CST 2021
谷歌浏览器 打开网页出现 out of memory
GCC基础知识
Use openmap and ArcGIS to draw maps and transportation networks of any region, and convert OMS data into SHP format
Data Lake: spark, a distributed open source processing engine