big number pro
blem
desc
ript
io
n\colorproblem description
proble
mdes
crip
tion
i np
ut
\colorinput
inpu
tinput consists of several lines of integer numbers. the first line contains an integer n
nn, which is the number of cases to be tested, followed by n lines, one integer 1
<=n
<=1
07
1<=n<=10^7
1<=n
<=1
07on each line.
o ut
pu
t\coloroutput
output
s am
plei
nput
\colorsample input
sample
inpu
t
2
1020
sam
pleo
utpu
t\colorsample output
sample
outp
ut
7
19
題目就是要你求n!n!
n!的位數,可以暴力求,也可以使用斯特林公式o(1
)o(1)
o(1)
解決。斯特林公式:n!≈
2πn(
ne)n
n!≈2πn
(en
)n,
我們知道求乙個數n
nn的位數的公式是:log
10(n)
+1
log_(n)+1
log10
(n)+
1,那麼對斯特林公式取對數,可以得到dig
it=l
og10(
n!)+
1=
0.5log
10(2π
n)+n
log10
ne
digit=log10(n!)+1=0.5log_(2\pi n)+nlog_ \frac
digit=
log1
0(n!
)+1=
0.5l
og10
(2π
n)+n
log1
0en
。
#include
using
namespace std;
using ll =
long
long
;const
int n =
1e5+10;
const
int inf =
0x3f3f3f3f
;const
double eps =
1e-7
;#define endl '\n'
#define pb(a) push_back(a)
#define all(x) x.begin(), x.end()
#define size(x) int(x.size())
#define ios ios::sync_with_stdio(0);
#define e 2.71828182
intmain()
return0;
}
Big Number階乘位數計算 斯特林公式
題目大致意思是輸入乙個t,然後接下來t行中輸入n並計算每一行中n的階乘的位數 解題思路 如果此題不是大數的話可以用對數函式性質 log10 1 2 3 4 5.log10 1 log10 2 附上 注意sum是double int main if n 1 sum 1 cout 向上取整函式 retu...
斯特林公式
斯特林公式是一條用來取n階乘近似值的數學公式。一般來說,當n很大的時候,n階乘的計算量十分大,所以斯特靈公式十分好用。斯特林公式可以用來估算某數的大小,結合lg可以估算某數的位數,或者可以估算某數的階乘是另乙個數的倍數。stirling公式的意義在於 當n足夠大時,n 計算起來十分困難,雖然有很多關...
斯特林公式
斯特林公式的常見表示形式 顯而易見,這個公式主要是用來求近似的階乘的值的,在競賽中往往只採用第乙個形式,其精確度已經足夠用來求階乘位數了.lg n lg 2 n 2 n lg n lg e 這個公式就是圖中第乙個式子左右同時求對數得到的.不難發現,10x,10 x 1 之間囊括了所有長度為x 1的數...