-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathLENGFACT.cs
28 lines (25 loc) · 872 Bytes
/
LENGFACT.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using System;
// https://www.spoj.com/problems/LENGFACT/ #formula #math
// Calculates the number of digits in a factorial.
public static class LENGFACT
{
// Not sure how to rate this problem. Kind of reminds me of FCTRL. I gave up trying
// to figure out a smart way and BigInteger was clearly going to be too slow. So:
// https://oeis.org/A034886, https://mathoverflow.net/q/19170
public static long Solve(long n)
=> n < 2 ? 1
: (long)Math.Ceiling(Math.Log10(2 * Math.PI * n) / 2 + n * Math.Log10(n / Math.E));
}
public static class Program
{
private static void Main()
{
int remainingTestCases = int.Parse(Console.ReadLine());
while (remainingTestCases-- > 0)
{
long n = long.Parse(Console.ReadLine());
Console.WriteLine(
LENGFACT.Solve(n));
}
}
}