hdu1042

题目大意: 求 n!(可能会超过整数范围,这里用数组模拟n!的值)

http://acm.hdu.edu.cn/showproblem.php?pid=1042

AC代码:

/**

*数组模拟n!

*/

#include<iostream>

#include<cstdio>

#include<string.h>

using namespace std;

int a[40001];

int main()

{

int n;

while(cin>>n){

memset(a,0,sizeof(a));

a[0]=1;

//cout<<a[10000]<<endl;

int flag=0;

for(int j=2;j<=n;j++){

for(int i=0;i<=40000;i++){

int sum=j*a[i]+flag;

flag=sum/10;

a[i]=sum%10;

}

}

int i;

for(i=40000;!a[i];i--);

// cout<<i<<endl;

for(int j=i;j>=0;j--){

cout<<a[j];

}

cout<<endl;

}

return 0;

}

时间: 2025-01-02 00:58:28

hdu1042的相关文章

HDU1042(N!)题解

HDU1042(N!)题解 以防万一,题目原文和链接均附在文末.那么先是题目分析: [一句话题意] 计算N的阶乘并输出. [题目分析] 题给范围上限是10000,那么毫无疑问是大数题.之前我整理过各种大数的代码并且改了改然后所谓封装了一下,于是这道题就直接用了个类似的代码修改了一下,然后...交上去就对了(喂..).但是作为题解,怎么着也得把做法解释清楚吧.. 以下为c语言代码(虽然是cpp提交的,也带了一堆cpp头文件),也附带了代码解释.代码很好懂,看看解释应该看得明白.还有...如果你是写

HDU1042(N!:设4为基数)

N! Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 74215    Accepted Submission(s): 21549 Problem Description Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N! Input One N in on

N!---hdu-1042

N! Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 65262    Accepted Submission(s): 18665 Problem Description Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N!   Input One N in

JAVA大数乘法 HDU1042

1 import java.math.*; 2 import java.util.Scanner; 3 4 5 public class Main{ 6 public static void main(String[] args){ 7 int a; 8 Scanner cin = new Scanner(System.in); 9 while(cin.hasNext()) 10 { 11 BigInteger ans=BigInteger.ONE; 12 a=cin.nextInt(); 13

HDU1042 N!(大整数类应用)

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 1 2 3 Sample Output 1 2 6 Code: #include <iostream> #incl

hdu1042 N!(大数)

N! Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 75069    Accepted Submission(s): 21870 Problem Description Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N! Input One N in o

杭电HDU1042(有点坑的高精度)

题目:http://acm.hdu.edu.cn/showproblem.php?pid=1042 题意: Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N! 是不是很简单呢? 一般方法: #include<iostream> #include<cstring> using namespace std; const int MAXN = 10000; int a[MAXN]; int main() { in

HDU1042 N! 大数的阶乘

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1042 由于数字特别大, 所以用数组来模拟. 经测试, 数组大小开50000 可过. 附AC代码, 欢迎大神指点~ #include <cstdio>#include <cstring> const int maxn = 50000 + 100;int a[maxn];void solve(int n){ memset(a, 0, sizeof(a)); a[0] = 1; int p

HDU1042 A * B Problem Plus

A * B Problem Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 24620    Accepted Submission(s): 6271 Problem Description Calculate A * B. Input Each line will contain two integers A and B. P