java 10000的阶乘
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)); }
}
}
java 10000的阶乘的更多相关文章
- java代码求阶乘n!
面试过程中总是遇到要求写一段Java代码求阶乘.下面就是就是两种求阶乘 n! 的方法: 1.使用递归求解n! public int doFactorial(int n){ if(n<0){ re ...
- Java递归实现阶乘
import java.util.Scanner; public class Factorial { public static void main(String[] args) { Scanner ...
- Java 计算N阶乘末尾0的个数-LeetCode 172 Factorial Trailing Zeroes
题目 Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in ...
- Java - n的阶乘计算
用递归方法,求10!的阶乘 分析: f(n) = n * f(n-1) n != 1 ----- 递推公式 f(n) = 1 ...
- Java实现递归阶乘
public class Factorial{ public static void main(String[] args){ for (int i = -5; i <= 5; i++) { S ...
- 中石油-高精度阶乘-java
问题 F: [高精度]高精度阶乘 时间限制: 1 Sec 内存限制: 64 MB提交: 49 解决: 13[提交][状态][讨论版] 题目描述 <魔法宝典>对于修罗王是如此重要,是因为 ...
- JAVA中使用递归和尾递归实现1000的阶乘的比较
在JAVA中求阶乘首先遇到的问题就是结果溢出,不管是使用int还是long,double都无法表示1000!这么大的天文数字,这里暂且用BigInteger解决这个问题! 下面是使用递归和尾递归分别计 ...
- HDoj-1042 大数阶乘
N! Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submis ...
- Java的IO文档
1. File类 1.1. File类说明 存储在变量,数组和对象中的数据是暂时的,当程序终止时他们就会丢失.为了能够永 久的保存程序中创建的数据,需要将他们存储到硬盘或光盘的文件中.这些文件 ...
随机推荐
- C - Tram
Problem description Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n i ...
- 可变长度参数列表(Stering...aaa)
- Shiro图解
- oracle命令行登录(默认用户名和密码)
oracle数据库安装成功之后会有默认的用户名和密码,之前因为没有整理,每次用的时候都要百度很麻烦,所以现在把这些都整理一下,也方便以后使用: 使用scott用户连接:使用sys用户连接:使用syst ...
- angularJS之ng-bind与{{}}取值的区别
1:{{ }} 是等页面加载完后,再取值. 2:ng-bind 它是在页面加载的时候,是不会显示{{name}}这种变量出来. 3:ng-bind 可以解决 ng 页面闪烁加载问题. 4:ng-bin ...
- javascript 基础知识点
NaN; // NaN表示Not a Number,当无法计算结果时用NaN表示 Infinity; // Infinity表示无限大,当数值超过了JavaScript的Number所能表示的最大值时 ...
- 【sqli-labs】 less33 GET- Bypass AddSlashes (GET型绕过addslashes() 函数的宽字节注入)
和less32一样,对关键字符进行了添加\ 关于addslashes()函数 payload和less32一样 http://192.168.136.128/sqli-labs-master/Less ...
- swiper和Navigator组件
<swiper class="index-banner" indicator-dots="{{true}}" autoplay="{{true} ...
- Graph network classification(As a beginner, continue to update)
Data arrangement 1.Reference Webs http://nlp.csai.tsinghua.edu.cn/~tcc/ https://blog.csdn.net/a60964 ...
- 【第一课】kaggle初识
Evernote Export Crowdflower搜索结果相关性 文件和数据描述 train.csv训练数据集包括: id:产品ID查询:使用的搜索词 product_description:完整 ...