java 10000的阶乘
2024-08-31 06:10:47
package test;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner; public class MyTest { public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
List<Integer> result = new ArrayList<Integer>();
int carry = 0;
int digit = 1;
int temp = 1;
int i,j;
result.add(1);
for(i = 2;i<=n;i++){
for(j = 0,carry = 0;j<digit;j++){
temp = result.get(j)*i+carry;
result.set(j, temp%10000);
carry = temp/10000;
} while(carry != 0){
result.add(digit++, carry%10000);
carry/=10000;
}
}
int count = 1;
System.out.print(result.get(digit-1));
for(i = digit-1;i>=1;i--){
count++;
if(result.get(i-1)<10){
System.out.print("000");
}else if(result.get(i-1)<100){
System.out.print("00");
}else if(result.get(i-1)<1000){
System.out.print("0");
}
System.out.print(result.get(i-1)); }
}
}
最新文章
- WindowsError的错误代码详解
- 快速上手RaphaelJS--Instant RaphaelJS Starter翻译(二)
- sikuli实战记录
- [转]HttpURLConnection的使用
- TCP经受时延的ACK
- linux mint 五笔安装方法
- C#编写自动关机程序复习的知识
- 27_Blog Reader
- [ArcGIS必打补丁]ArcGIS 10.1 SP1 for (Desktop, Engine, Server) Quality Improvement Patch
- MySql 学习之路-聚合函数
- html css hover也会冒泡
- python之路---模块
- windwos安装RabbitMQ
- webService上传图片
- War Chess (hdu 3345)
- C#快速删除bin和obj文件夹的方法
- hdu 5826 physics 物理题
- Android 开发自己的网络收音机2——电台列表(SlidingMenu侧滑栏)
- php array_rand()函数从数组中随机选择一个或多个元素
- tensorflow模型持久化保存和加载
热门文章
- Java实现九宫格
- Leetcode0005--Longest Palindromic Substring 最长回文串
- hibernate_08_关联映射_一对多
- python3 str类型
- Cell期刊论文:为什么计算机人脸识别注定超越人类?(祖母论与还原论之争)
- SLAM: Ubuntu14.04_Kylin安装ROS-Indigo
- vue路由中的 Meta
- PAT_A1116#Come on! Let&#39;s C
- 【剑指Offer】29、最小的K个数
- let、var、const用法区别