不要让昨天 占据你的今天 夏午晴天

夏午晴天

N! (大数,优化)

Problem Description

输出N的阶乘。(注意时间限制150ms&&注意不能打表后输出)

打表的定义:在本地主机预先计算出了每个值对应的答案,并把输入和输出的映射直接写入所提交的代码。

Input

多组输入到文件结尾
每组输入一个整数n,(0<=n<=23)。

Output

每组测试数据输出一行,为n!。

Sample Input

1
2

Sample Output

1
2

 1 #include <iostream>
 2 #include <stdio.h>
 3 using namespace std;
 4 #define ll long long
 5 int main(){
 6     ll n;
 7     while(cin >> n){
 8         ll cmp = 1;
 9         string str = "";
10         for(int i = 2; i <= n; i++){
11             int x = i;
12             while(x%5 == 0){
13                 if(x%2 == 0){
14                     x /= 2;
15                 }
16                 else cmp /= 2;
17                 x /= 5;
18                 str += '0';
19             }
20             cmp *= x;
21         }
22         cout << cmp << str << endl;
23     }
24 }

 

posted on 2017-05-04 09:36  夏晴天  阅读(386)  评论(0编辑  收藏  举报

导航

Live2D