1003 -- 计算N!
2015-08-29 03:13
351 查看
计算N!
Time Limit:1000MS Memory Limit:65536K
Total Submit:931 Accepted:209
Description
Description:
你的好友小王最近学了一个新的运算法则——阶乘,但他很懒,不想一步一步计算,早知道你是一个程序高手,所以他想让你来帮他编一个程序,能马上得到N的阶乘。
Input
Input:
输入包含若干行数据,每行都有一个整数N(0<=N<=500)。
Output
Output:
与输入相对应每行输出N的阶乘。
Sample Input
Sample Output
Source
ahstu@ICPC01
Time Limit:1000MS Memory Limit:65536K
Total Submit:931 Accepted:209
Description
Description:
你的好友小王最近学了一个新的运算法则——阶乘,但他很懒,不想一步一步计算,早知道你是一个程序高手,所以他想让你来帮他编一个程序,能马上得到N的阶乘。
Input
Input:
输入包含若干行数据,每行都有一个整数N(0<=N<=500)。
Output
Output:
与输入相对应每行输出N的阶乘。
Sample Input
Sample Input: 2 4
Sample Output
Sample Output: 2 24
Source
ahstu@ICPC01
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace AK1003 { /// <summary> /// 大数阶乘 /// 本代码参考老赵以前写过的大数阶乘代码 /// </summary> class Program { static void Main(string[] args) { string sb; int i, j, temp, start, sc, N = 1200; while ((sb = Console.ReadLine()) != null) { int n = int.Parse(sb); int[] a = new int ; for (a[0] = 1, i = 1; i <= n; i++) for (sc = 0, j = 0; j < N; j++) { temp = a[j] * i + sc;//当前这一位的数乘上i,然后加上后面来的进位 sc = temp / 10;//sc代表进位 a[j] = temp % 10;//本位保留模后的结果 } //数据是倒着存的,即1*2*3*4=24,存是是按420000000...保存的,一直有N=1200位 for (start = N - 1; a[start] == 0; --start) ;//这里是确定从后面哪一位开始输出,从后向前输出 for (; start >= 0; --start) Console.Write(a[start]); Console.WriteLine(); } } } }
相关文章推荐
- Hello World Using Struts 2
- 1002 -- 手机靓号
- 1095. Cars on Campus (30)
- 1001 -- ACM"水题"
- mysql导入sql文件时乱码问题
- 1000 -- A+B Problem
- 视觉交互的知识总结
- 【如何通过广域网访问局域网的服务器?】
- 1、iOS 开发之基础控件
- 前序遍历和中序遍历树构造二叉树 查看运行结果
- 面试题:字符串查找
- poj 2836 Rectangular Covering(状态压缩dp)
- [HDU 1506 Largest Rectangle in a Histogram] ...类dp?...
- MYSQL安装遇到MySQL-server conflicts with错误(mysql5.6.17)
- 关于重连测试的一点研究
- 中序遍历和后序遍历树构造二叉树
- Shader基本语法
- 635 Oh, my goddess【优先队列+bfs】
- Unity优化大全(八)之 GPU-Ligh和其他
- ETCD高可用特性学习