nyist28大数阶乘
http://acm.nyist.net/JudgeOnline/problem.php?pid=28
大数阶乘
- 描述
- 我们都知道如何计算一个数的阶乘,可是,如果这个数很大呢,我们该如何去计算它并输出它?
- 输入
- 输入一个整数m(0<m<=5000)
- 输出
- 输出m的阶乘,并在输出结束之后输入一个换行符
- 样例输入
-
50
- 样例输出
-
30414093201713378043612608166064768844377641568960512000000000000 分析:
说白了就是利用数组存储数字的每一位
c++版:
#include <iostream>
using namespace std; int main()
{
int a[]={,};
int m,i,j,len=,tem,jin;
cin>>m;
for(i=;i<=m;i++)
{
jin=;
for(j=;j<=len;j++)
{
tem=a[j]*i+jin;
a[j]=tem%;
jin=tem/;
if(j==len&&jin!=)
len++;
}
}
for(i=len;i>=;i--)
cout<<a[i];
cout<<endl;
return ;
}
c语言版:
#include <stdio.h>
int a[];
int main()
{
int carry,n,j;
int digit;
int temp,i;
while(scanf("%d",&n)!=EOF){
a[]=;digit=;
for(i=; i<=n; i++)
{
for(carry=,j=; j<=digit; ++j)
{
temp=a[j-]*i+carry;
a[j-]=temp%;
carry=temp/;
}
while(carry)
{a[++digit-]=carry%;
carry/=;
}
}
for(int k=digit; k>=; --k)
printf("%d",a[k-]);
printf("\n");
printf("length=%d\n",digit);
}
return ;
}
nyist28大数阶乘的更多相关文章
- 大数阶乘(c语言)
大数阶乘.代码比较简单. #include<stdio.h> #include<string.h> #define MAXN 25000 // 如果你的阶乘N比较大,建议大一点 ...
- 【大数阶乘】NYOJ-28
大数阶乘 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 我们都知道如何计算一个数的阶乘,可是,如果这个数很大呢,我们该如何去计算它并输出它? 输入 输入一个整数 ...
- 大数阶乘 nyoj
大数阶乘 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 我们都知道如何计算一个数的阶乘,可是,如果这个数很大呢,我们该如何去计算它并输出它? 输入 输入一个整数 ...
- 【ACM】大数阶乘 - Java BigInteger实现
大数阶乘 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 我们都知道如何计算一个数的阶乘,可是,如果这个数很大呢,我们该如何去计算它并输出它? 输入 输入一个整数 ...
- nyoj___大数阶乘
http://acm.nyist.net/JudgeOnline/problem.php?pid=28 大数阶乘 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 我们都知 ...
- 大数阶乘(c++实现)
#include <iostream>using namespace std;#define N 1000int BigNumFactorial(int Num[], int n);voi ...
- HDU 1133 Buy the Ticket (数学、大数阶乘)
Buy the Ticket Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- 大数阶乘(C/C++)
高精度的运算在Java中是很容易实现的,就像 a + b Problem 一样,因为Java提供了相应的类库和API:但是在 C/C++ 当中就没有那么现成的类和API来让你调用了.本着“自己动手,丰 ...
- #035 大数阶乘 PTA题目6-10 阶乘计算升级版 (20 分)
实际题目 本题要求实现一个打印非负整数阶乘的函数. 函数接口定义: void Print_Factorial ( const int N ); 其中N是用户传入的参数,其值不超过1000.如果N是非负 ...
随机推荐
- 迷宫bfs POJ3984
#include<stdio.h> int map[5][5]={0,1,0,0,0, 0,1,0,1,0, 0,0,0,0,0, 0,1,1,1,0, ...
- ArcGIS Server发布服务,打包成功,发布失败
打包成功,发布失败 部分解决方案: ① 查看Server对于源数据所在文件夹是否有读写权限,若无赋予Server账户至少读写权限.读写权限的赋予:对应存放数据的文件夹上右键→属性→ 安全 赋予ar ...
- PureBasic 读取文件中一行的两个数据例子
, "Test1.txt") ; if the file could be read, we continue... , "Test2.txt") ) = ; ...
- [转载]推荐不伤眼睛的文字背景色 VS背景色
天天使用电脑要主要保护眼睛.下面介绍下不伤眼睛的文字背景色 苹果绿 RGB 204,255,204 #CCFFCC 杏仁黄 rgb 250 249 222 #FAF9DE 青草绿 rgb 227 23 ...
- 低功耗蓝牙4.0BLE编程-nrf51822开发(4)
蓝牙是一种短距离的通讯方式,它设计的意图是取代电子便携设备之间的有线电缆连接.蓝牙的主要特性是健壮性.低功耗.成本低,它工作于免费的2.4无线传输频段. 蓝牙有两种技术系统:基本速率Basic Rat ...
- 非Controller类无法使用Service bean解决方案
尝试方案: 1 在Spring的配置文件springmvc.xml中,增加扫描项base-package="zxs.ssm.util",增加你需要使用service的类所在的包 ...
- SQL Server中的Image数据类型的操作
原文:SQL Server中的Image数据类型的操作 准备工作,在库Im_Test中建立一张表Im_Info,此表中有两个字段,分别为Pr_Id (INT),Pr_Info (IMAGE),用来存储 ...
- One Time Auth
One Time Auth One-time authentication (shortened as OTA) is a new experimental feature designed to i ...
- 【转】Android 获得view的宽和高
转自:http://blog.csdn.net/yangdeli888/article/details/25405263 Android 获得view的宽和高 分类: android 技术点项目20 ...
- LeetCode Shortest Palindrome
原题链接在这里:https://leetcode.com/problems/shortest-palindrome/ 题目: Given a string S, you are allowed to ...