Commit adae263 1 parent e048725 commit adae263 Copy full SHA for adae263
File tree 1 file changed +7
-4
lines changed
1 file changed +7
-4
lines changed Original file line number Diff line number Diff line change 3
3
4
4
class DigitsOfE
5
5
{
6
+ private static readonly double LogOfTau = Math . Log ( Math . Tau ) ;
7
+ private static readonly double LogOfTen = Math . Log ( 10 ) ;
8
+
6
9
public static void Main ( string [ ] args )
7
10
{
8
11
int n ;
@@ -45,7 +48,7 @@ public static void Main(string[] args)
45
48
{
46
49
if ( b == a + 1 )
47
50
{
48
- return ( new BigInteger ( 1 ) , new BigInteger ( b ) ) ;
51
+ return ( BigInteger . One , new BigInteger ( b ) ) ;
49
52
}
50
53
var mid = ( a + b ) / 2 ;
51
54
var ( pLeft , qLeft ) = SumTerms ( a , mid ) ;
@@ -79,12 +82,12 @@ static int BinarySearch(int n)
79
82
80
83
static bool TestK ( int n , int k )
81
84
{
82
- if ( k < 0 )
85
+ if ( k <= 0 )
83
86
{
84
87
return false ;
85
88
}
86
- var lnKFactorial = k * ( Math . Log ( ( double ) k ) - 1 ) + 0.5 * Math . Log ( Math . PI * 2 ) ;
87
- var log10KFactorial = lnKFactorial / Math . Log ( 10 ) ;
89
+ var lnKFactorial = k * ( Math . Log ( ( double ) k ) - 1 ) + 0.5 * LogOfTau ;
90
+ var log10KFactorial = lnKFactorial / LogOfTen ;
88
91
return log10KFactorial >= ( double ) ( n + 50 ) ;
89
92
}
90
93
}
You can’t perform that action at this time.
0 commit comments