当前位置:网站首页>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);
}
}
边栏推荐
- Classes and objects (I)
- Word如何查看文档修改痕迹?Word查看文档修改痕迹的方法
- Command line interactive tools (latest version) inquirer practical tutorial
- Download addresses of various versions of MySQL and multi version coexistence installation
- Reply from the Secretary of jindawei: the company is optimistic about the market prospect of NMN products and has launched a series of products
- 虚拟偶像的歌声原来是这样生成的!
- 搭建手机APP需要用到什么服务器
- Spark的算子操作列表
- MySQL定时调用预置函数完成数据更新
- 2022杭电多校联赛第四场 题解
猜你喜欢

如何让照片中的人物笑起来?HMS Core视频编辑服务一键微笑功能,让人物笑容更自然

What are the core features of the digital transformation of state-owned construction enterprises?

电脑无法打开excel表格怎么办?excel打不开的解决方法

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

Correct user dragging method
![学术 | [LaTex]超详细Texlive2022+Tex Studio下载安装配置](/img/4d/f8c60c0fbbd98c4da198cfac7989fa.png)
学术 | [LaTex]超详细Texlive2022+Tex Studio下载安装配置

虚拟偶像的歌声原来是这样生成的!

【无标题】

UE plays video in scene or UMG

Use jupyter (2) to establish shortcuts to open jupyter and common shortcut keys of jupyter
随机推荐
Software test interview questions (4)
pulsar起client客户端时(client,producer,consumer)各个配置
IOS interview preparation - Online
Use openmap and ArcGIS to draw maps and transportation networks of any region, and convert OMS data into SHP format
def fasterrcnn_resnet50_fpn()实例测试
Recommendation system of online education
Opencv environment construction
MySQL定时调用预置函数完成数据更新
Flutter 手势监听和画板实现
Auto.js脚本开发入门
Opencv learning 1 (environment configuration)
Glory 2023 push, push code ambubk
带你搞懂 Kubernetes 集群中几种常见的流量暴露方案
Command line interactive tools (latest version) inquirer practical tutorial
RecyclerView通过DPAD按键上下切换焦点 切换到界面外的控件时焦点会左右乱跳
(heap sort) heap sort is super detailed, I don't believe you can't (C language code implementation)
img 响应式图片的实现(含srcset属性、sizes属性的使用方法,设备像素比详解)
[C] PTA 6-8 finding the height of binary tree
Recyclerview switches the focus up and down through the dpad key. When switching to the control outside the interface, the focus will jump left and right
SGuard64.exe ACE-Guard Client EXE:造成磁盘经常读写,游戏卡顿,及解决方案