HDU 1018 Big number 斯特林公式,lnN!=NlnN-N+0.5*ln(2*N*pi)

这道数学题用到了数论中的一个公式,叫做斯特林公式,lnN!=NlnN-N+0.5*ln(2*N*pi)

//============================================================================ // Name : HDU.cpp // Author : lonelycatcher // Version : // Copyright : Your copyright notice // Description : Hello World in C++, Ansi-style //============================================================================  #include <iostream> #include<stdio.h> #include<cstdlib> #include<math.h> using namespace std; #define PI 3.141592653 int N; void solve(int num) { double ans=(num*log(num)-num+0.5*log(2*num*PI))/(log(10));

    printf("%d\n",(int)ans+1); } int main() { int T;

    scanf("%d",&T); while(T--) {

        scanf("%d",&N);

        solve(N); } return 0; }

你可能感兴趣的:(number)