高精度练习(hdoj1042)

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

 

#include <stdio.h>
#include <stdlib.h>
char* myblog[] = {
    "http://www.cnblogs.com/archimedes/",
    "hdoj1042",
    "mail: codingwu@gmail.com"};

int a[50000];

void count(int n)
{
    int i, flag, digit, j, t;
    a[0] = 1;
    digit = 1;
    j = 1;
    for(i = 2; i <= n; i++) {
        flag = 0;
        for(j = 0; j < digit; j++) {
            t = a[j] * i + flag;
            if(t >= 10) {
                a[j] = t % 10;
                flag = t / 10;
            } else {
                a[j] = t;
                flag = 0;
            }
        }
        if(flag) {
            while(flag) {
                a[j] = flag % 10;
                flag /= 10;
                digit++;
                j++;
            }
        }
    }
    for(i = j - 1; i >= 0; i--)
        printf("%d", a[i]);
    printf("\n");
}

void solve()
{
    int n;
    while(scanf("%d", &n) != EOF) {
        if(n == 0) printf("1\n");
        else count(n);
    }
}

int main()
{
    solve();
    return 0;
}
时间: 2024-08-03 05:34:50

高精度练习(hdoj1042)的相关文章

HDU 4099 字典树+高精度

题意:给出某项斐波那契数的前几位,让输出最小的一项前缀为这个串的项数. 先高精度算出前100000项斐波那契的前50位.并把前40位存进字典树预处理一下.字典树节点值存为第几项.然后输入字符串直接查找. #include <iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; #define N 50 int fib[3][N+1]; cla

为Windows实现一个连续更新,高精度的时间供应器

本篇文章假定你熟悉 C++ 和 Win32 API 概要 从 Windows NT 里获得的时间戳(Timestamp),根据你所使用的硬件,其最大精度为 10 到 15 毫秒.但是, 有时候你需要时间标签频繁事件时,获得更高的精度更能令人满意.举个例子,如果你要与线程打交道,或者以间隔不低于 10 毫秒的频率实现某些其它任务时该怎么办?为了获得更好的精度,建议的方法包括使用性能计数器和系统时间一起去计算更小的时间增量.然而使用性能计数器技术有其自身的问题.本文将揭示一种可行的途径来克服该方法固

C++高精度定时器

//////////////////////////////////////////////////////////////////////// /////// // KTimer.h // // Windows Graphics Programming Win32 GDI and DirectDraw // Feng Yuan // Publisher: Prentice Hall PTR // First Edition December 01, 2000 // // 高精度纳秒计时器, 最

UVa 10247 Complete Tree Labeling:组合数学&amp;amp;高精度

10247 - Complete Tree Labeling Time limit: 15.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1188 A complete k-ary tree is a k-ary tree in which all leaves have same d

UVa 748/POJ 1001 Exponentiation:浮点高精度求幂&amp;amp;正则表达式的应用

748 - Exponentiation Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=97&page=show_problem&problem=689 http://poj.org/problem?id=1001 Problems involving the computation of exact values

UVa 623 500! (高精度阶乘)

623 - 500! Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=564 In these days you can more and more often happen to see programs which perform some useful

C++中获取高精度时间差

解决一个问题通常有多种方法, 我们总想找到最高效的,所以需要对比不同算法执行所用的时间.可惜的是,C++中提供的方法一般只能精确到毫秒级. 提供一种更加精确的方法.编写一个函数,可以在C++中这样写: __declspec (naked) unsigned __int64 GetCpuCycle( void ) { _asm { rdtsc ret } } RDTSC的返回值存放在EDX EAX中, EDX为高32位,EAX为低32位.这里的 RDTSC 指令( Read Time Stamp

for-求问高精度算法内语句的意思?

问题描述 求问高精度算法内语句的意思? 这段程序中 语句 if(b1[0]==45) { an--; fa=-1;ai=0;} /*判断数组的符号 */ if(b2[0]==45) { bn--; fb=-1;bi=0;} 是什么意思求大神讲解谢谢 #include #include #include #include int anbnfa=1fb=1; /* 把anbnk设为全局变量an纪录第一个高精度数组的位数bn纪录第二个高精度数组的位数k纪录输出结果的位数*/ char b1[250]

poj 1503 Integer Inquiry【高精度】

这题总算是没有那么水的感觉了,不过还是水题,哈哈哈...题目主要是求高精度----大数的和,我专门写了一个add函数处理,sum和VeryLongIntegers是两个全局的变量,开始我还准备把sum也写成char型的字符串,但是考虑到结尾的'\0',那不是自找麻烦..果断换成int型数组,这样就容易处理多了. 在add函数中,我把VeryLongIntegers又反转了一次(即变成低位在前),也换成一个int型的数组,这样就变成两个int型数组的高精度加法了... 开始还觉得可能会WA一次,不