(n: bigint)
| 25 | } |
| 26 | |
| 27 | function digitCount(n: bigint): number { |
| 28 | if (n === 0n) return 1 |
| 29 | if (n < 0n) n = -n |
| 30 | let count = 0 |
| 31 | // Fast path: skip 15 digits at a time |
| 32 | const big15 = 1000000000000000n |
| 33 | while (n >= big15) { |
| 34 | n /= big15 |
| 35 | count += 15 |
| 36 | } |
| 37 | // Remaining digits |
| 38 | let r = Number(n) |
| 39 | while (r >= 1) { |
| 40 | r /= 10 |
| 41 | count++ |
| 42 | } |
| 43 | return count |
| 44 | } |
| 45 | |
| 46 | const TEN_BIGINT = 10n |
| 47 |