解题思路:用大整形
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 人评分
C语言程序设计教程(第三版)课后习题8.8 (C语言代码)浏览:642 |
母牛的故事 (C语言代码)浏览:551 |
简单的a+b (C语言代码)浏览:582 |
1048题解(读入回车问题)浏览:566 |
字符串的输入输出处理 (C语言代码)浏览:1017 |
矩形面积交 (C语言代码)浏览:1314 |
交换Easy (C语言代码)浏览:763 |
格式化数据输出 (C语言代码)浏览:822 |
C语言程序设计教程(第三版)课后习题12.2 (C语言代码)浏览:768 |
C语言程序设计教程(第三版)课后习题1.6 (C语言代码)浏览:673 |