牟文琳


私信TA

用户名:dotcpp0716155

访问量:648

签 名:

等  级
排  名 679
经  验 3841
参赛次数 0
文章发表 60
年  龄 0
在职情况 学生
学  校 淄博职业学院
专  业

  自我简介:

解题思路:用大整形

package test;
//题目 2114: 信息学奥赛一本通T1173-阶乘和
import java.util.Scanner;
import java.math.BigInteger;
public class t_2114 {
public static void main(String args[]) {
	int n;
	BigInteger sum=new BigInteger("0");//阶乘总和
	BigInteger temp1=new BigInteger("1");//用于单次阶乘的合
	BigInteger temp3=new BigInteger("1");//用于置零
Scanner sc=new Scanner (System.in);
n=sc.nextInt();
	int temp2;//用来暂存每次的值
	for(int i=1;i<=n;i++) {
		temp2=i;
	temp1=temp3;//每次开始前用于存储每次阶乘的值置一
		while (temp2!=0) {
			String str=Integer.toString(temp2);//将整形转换为字符串
BigInteger x=new BigInteger(str);
			temp1=temp1.multiply(x);
			temp2--;
			}
		sum=sum.add(temp1);//相加每次结果
	}
	System.out.println(sum);
	
}
}


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答

代码解释器

  评论区