打印100的阶乘(大数问题,Java好解)
来源:互联网 发布:网络暴力英文ppt 编辑:程序博客网 时间:2024/06/08 10:32
FCTRL2 - Small factorials
You are asked to calculate factorials of some small positive integers.
Input
An integer t, 1<=t<=100, denoting the number of testcases, followed by t lines, each containing a single integer n, 1<=n<=100.
Output
For each integer n given at input, display a line with the value of n!
Example
Sample input:
41253
Sample output:
121206
#include <iostream> #include <vector> std::vector<int> v; void fact(int n) { v.clear(); // ! v.resize(200, 0); v[199] = 1; for(int i = 2; i <= n; ++i) { int carry = 0; for(int j = 199; j >= 0; --j) { v[j] = v[j] * i + carry; carry = v[j] / 10; v[j] %= 10; } } } int main() { int T; std::cin >> T; int n; while(T--) { std::cin >> n; fact(n); int i = 0; while(v[i] == 0) { ++i; } for(; i < 200; ++i) { std::cout << v[i]; } std::cout << std::endl; } return 0; }import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.math.BigInteger;/****************************************************************************************************************/public class Main { public static void main(String[] args)throws IOException{ BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); BigInteger[] fac = new BigInteger[101]; fac[0] = fac[1] = BigInteger.ONE; for(int i = 2;i <= 100;i++) { BigInteger temp = BigInteger.valueOf(i); fac[i] = fac[i-1].multiply(temp); } int t = Integer.parseInt(bf.readLine()); while(t-- > 0){ int num = Integer.parseInt(bf.readLine()); System.out.println(fac[num]); } }}
阅读全文
0 0
- 打印100的阶乘(大数问题,Java好解)
- C打印 大数的 阶乘
- 大数阶乘(100的阶乘)
- 大数的阶乘问题
- java竞赛-大数阶乘问题
- java 大数的阶乘(一)
- 数学问题--大数的阶乘
- NYOJ 28.大数阶乘(大数问题)
- 【大数问题】大数阶乘
- 【java】求大数的阶乘
- java求大数的阶乘
- java 实现大数的阶乘
- java 大数阶乘(二)
- 1057 N的阶乘(大数阶乘)
- 白皮书 阶乘的精确度(大数阶乘)
- N的阶乘(大数阶乘算法)
- 求大数阶乘的位数(ACM Big Number问题)
- 杭电problem1018-大数(阶乘的位数问题)
- lua里实现table的序列化和反序列化
- 洛谷P3371 单源最短路径(Dijkstra+堆优化)
- noi 2017 游记
- tensorflow string_to_number to_double
- 【c#】DataTable分页处理
- 打印100的阶乘(大数问题,Java好解)
- B/S详解
- 一些字符串处理函数的实现!
- API之Boolean学习
- iOS 解决Mac电脑无法压缩zip压缩文件zip成cpgz
- 并发(四):同步一定要在同一把锁上
- 他们
- 我的第一篇博客
- java基础 常识