HDU 1042
来源:互联网 发布:数据库添加 insert 编辑:程序博客网 时间:2024/05/18 03:33
Problem Description
Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N!
Input
One N in one line, process to the end of file.
Output
For each N, output N! in one line.
Sample Input
123
Sample Output
126
题目意思很简单,求N的阶乘,因为到10000显然要用大数做,
个人感觉大数的题用JAVA做比较好,毕竟写起来比较省时间。
代码:
import java.util.Scanner;import java.math.*;public class Main {public static void main(String[] args) {Scanner cin = new Scanner(System.in);while(cin.hasNext()){ int a=cin.nextInt(); BigInteger b=new BigInteger("1"); for(int i=1;i<=a;i++) { BigInteger num = new BigInteger(i+""); //把整数变成大数的一个比较巧妙的方法 b=b.multiply(num); } System.out.println(b.toString()); System.gc(); } }}
0 0
- HDU 1042
- hdu 1042
- hdu 1042
- hdu 1042
- HDU 1042
- HDU 1042
- HDU 1042
- hdu 1042
- hdu 1042
- hdu 1042
- hdu 1042
- HDU 1042
- HDU-1042
- hdu 1042
- HDU 1042
- HDU 1042
- N! ---HDU 1042
- HDU 1042 N!
- 博弈 SG函数
- MySQL---数据库从入门走向大神系列(十)-Connection对象池、装饰模式与动态代理模式
- 使用android studio 连接海马玩模拟器
- MySQL使用SELECT INTO OUTFILE导出文本文件
- poj 2155 Matrix
- HDU 1042
- 函数传参中传递的是值还是引用?
- copy拷贝构造函数及拷贝和赋值函数的区别
- ubuntu一台服务器上部署多个tomcat
- thinkphp 缓存写入失败
- Mongodb 的中数据统计神器Map_Reduce的使用
- Java泛型-类型擦除
- SQL 盲注和脚本攻击防范
- python简单解决最大子列和问题