首页 技术 正文
技术 2022年11月20日
0 收藏 303 点赞 4,811 浏览 599 个字

Time Limit: 10 second

Memory Limit: 2 MB

问题描述

用高精度的方法,求n!的精确值(n的值以一般整数输入)。

Input

文件输入仅一行,输入n。

Output

输出n的阶层的值,最后用回车结束

Sample Input

10

Sample Output

3628800

【题解】

高精度乘单精度,只要处理好进位,调整数字长度就没有问题啦。

【代码】

#include <cstdio>int n,a[100000],l1 =1;void input_data()
{
scanf("%d",&n);
for (int i = 1; i <= 999;i++) //先初始化存高精度的数组
a[i] = 0;
a[1] = 1; //0! == 1
}void get_ans()
{
for (int i = 1;i <= n;i++) //从1一直乘到n
{
int x = 0; //x用来处理进位
for (int j = 1;j <= l1;j++)
{
a[j] = a[j] *i + x;
x = a[j] / 10;
a[j] = a[j] % 10;
}
while ( x > 0) //处理数字的长度
{
l1++;
a[l1] += x;
x = a[l1] / 10;
a[l1] = a[l1] % 10;
}
}
}void output_ans()
{
for (int i = l1;i >= 1;i--) //倒序输出
printf("%d",a[i]);
}int main()
{
input_data();
get_ans();
output_ans();
return 0;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,983
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,500
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,344
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,127
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,761
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,838