51Nod 1057 N的阶乘

输入N求N的阶乘的准确值。
 
Input
输入N(1 <= N <= 10000)
Output
输出N的阶乘
Input示例
5
Output示例
120

C语言:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
const int maxn=1e5+10;
const int mod=100000000;//精度可以自己设置
ll a[maxn],n,ans,pos=0;
int main()
{
    scanf("%lld",&n);
    a[0]=1;
    for(int i=1;i<=n;i++)
    {
        ans=0;
        for(int j=0;j<=pos;j++)
        {
            a[j]=a[j]*i+ans;
            ans=a[j]/mod;
            a[j]%=mod;
        }
        if(ans>0) a[++pos]=ans;
    }
    printf("%lld",a[pos]);
    for(int i=pos-1;i>=0;i--)
        printf("%0.8lld",a[i]);
    printf("\n");
    return 0;
}

Java语言:

import java.util.*;
import java.io.*;
import java.math.*;
public class Main
{
    public static void main(String[] args)
    {
        Scanner cin=new Scanner(System.in);
        int n;
        n=cin.nextInt();
        BigInteger m=BigInteger.ONE;
        BigInteger a=BigInteger.valueOf(n);
        BigInteger b=BigInteger.ONE;
        for(BigInteger i=BigInteger.ONE;i.compareTo(a)<=0;i=i.add(b))
        {
            m=m.multiply(i);
        }
        System.out.println(m);
    }
}    

 51Nod 1058 求N阶乘长度

输入N求N的阶乘的10进制表示的长度。例如6! = 720,长度为3。

 
Input
输入N(1 <= N <= 10^6)
Output
输出N的阶乘的长度
Input示例
6
Output示例
//求N阶乘的位数
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
int main()
{
    ll n;
    scanf("%lld",&n);
    ll ans=0.5*log10(2*pi*n)+n*log10(n*1.0/ei);//注+1不要跟在公式后面,否则1不成立
    printf("%lld\n",ans+1);
    ll pos=log10((long double)(sqrt(2*n*pi)))+n*log10((long double)n/ei);
    printf("%lld\n",ans+1);
    long long l=log10((long double)(sqrt(2*M_PI*n)))+n*log10((long double)n/M_E);
    printf("%.8lf %.8lf\n",M_PI,M_E);//M_PI  M_E 自带函数
    printf("%lld\n",l+1);
    return 0;
}

 

3

转载于:https://www.cnblogs.com/shinianhuanniyijuhaojiubujian/p/7204262.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值