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 }

 

转载于:https://www.cnblogs.com/jxust-jiege666/p/6805357.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值