hdu N!

news/2025/2/14 2:00:08/

HDU N!

N!

Time Limit : 10000/5000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 71   Accepted Submission(s) : 20

Font: Times New Roman | Verdana | Georgia

Font Size: ← →

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

Author

JGShining(极光炫影)

Statistic | Submit | Back
思路:
1:可以考虑用字符数组,然后再每位相乘,满十进位。但我感觉,可能太慢,于是就没用此方法。
2:就是考虑到此题的特殊性,输入的数并不大,只是在计算过程中结果大,因此,考虑到了有整形数组来存储数据,超过八位数(或者四位数)就把多出来的放到一个新的数组元素中。
就是相当于100000000位进制;
输出时,按八位输出,不满八位补零。
代码:
#include <iostream>
#include<cstdio>
#include<cmath>
using namespace std;
void factorial(int n)
{
    long long int a[10000];
    int i,j,c,m=0;
    a[0]=1;
    for(i=1; i<=n; i++)
    {
        c=0;
        for(j=0; j<=m; j++)
        {
            a[j]=a[j]*i+c;
            c=a[j]/100000000;
            a[j]=a[j]%100000000;
        }
        if(c>0)
        {
            m++;
            a[m]=c;
        }
    }
    printf("%I64d",a[m]);
    for(i=m-1; i>=0; i--)
        printf("%08I64d",a[i]);
printf("\n");
}
int main()
{
    int n;
    while(cin>>n)
    factorial(n);
    return 0;
}


http://www.ppmy.cn/news/397525.html

相关文章

N!

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

杭电--N!(大数)

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

极光炫影d acm

http://kennyblog.yculblog.com/archive.115560.html

「深度学习之优化算法」(六)遗传算法

1. 遗传算法简介 遗传算法(Genetic Algorithms&#xff0c;GA)是一种模拟自然中生物的遗传、进化以适应环境的智能算法。由于其算法流程简单&#xff0c;参数较少优化速度较快&#xff0c;效果较好&#xff0c;在图像处理、函数优化、信号处理、模式识别等领域有着广泛的应用。…

Kafka学习---4、消费者(分区消费、分区平衡策略、offset、漏消费和重复消费)

1、消费者 1.1 Kafka消费方式 1、pull&#xff08;拉&#xff09;模式&#xff1a;consumer采用从broker中主动拉取数据。 2、push&#xff08;推&#xff09;模式&#xff1a;Kafka没有采用这种方式。因为broker决定消息发生速率&#xff0c;很难适应所有消费者的消费速率。…

C语言之指针详解(3)

目录 本章重点 1. 字符指针 2. 数组指针 3. 指针数组 4. 数组传参和指针传参 5. 函数指针 6. 函数指针数组 7. 指向函数指针数组的指针 8. 回调函数 9. 指针和数组面试题的解析、 4. 数组参数、指针参数 我们来看一维数组传参 #include<stdio.h> void test(in…

Selenium基本用法

Selenium 提供了 8 种定位单个节点的方法&#xff0c;如下所示&#xff1a; 定位节点方法 方法 说明 find_element_by_id() 通过 id 属性值定位 find_element_by_name() 通过 name 属性值定位 find_element_by_class_name() 通过 class 属性值定位 find_element_by_tag_name()…

摩托罗拉展示远程充电 1米有效范围内可充数台手机

Motorola官方发布了关于motorola隔空充电技术的演示影片。片中将两部motorolaedge手机放在距离充电器1米与80厘米处&#xff0c;手机便可自动充电。 联想中国区手机业务部总经理"神奇的劲哥"还表示&#xff0c;motorola的隔空充电距离&#xff0c;已经可以做到远大于…