Big Number
calculator.
Add, multiply, divide or raise whole numbers of any length and keep every digit.
- Digits
- 60
- Prime test
- Composite
- Digit sum
- 207
This product has 60 digits and 197 bits. It is past both 2⁵³ − 1 and 2⁶³ − 1, so a spreadsheet rounds it and a 64-bit integer overflows. It has a factor other than 1 and itself.
Every digit
121,932,631,137,021,795,226,185,032,733,622,923,332,237,463,801,111,263,526,900
Working
- 1Exact product123,456,789,012,345,678,901,234,567,890 × 987,654,321,098,765,432,109,876,543,210 = 121,932,631,137,021,795,226,185,032,733,622,923,332,237,463,801,111,263,526,900
- 2Check: divide the product by B121,932,631,137,021,795,226,185,032,733,622,923,332,237,463,801,111,263,526,900 ÷ 987,654,321,098,765,432,109,876,543,210 = 123,456,789,012,345,678,901,234,567,890, remainder 0
How often each digit appears
Across the 60 digits, 2 is the most common, appearing 13 times. Digit 2 appears 13 times.
Digit counts
| Digit | Count |
|---|---|
| 0 | 5 |
| 1 | 10 |
| 2 | 13 |
| 3 | 12 |
| 4 | 1 |
| 5 | 3 |
| 6 | 6 |
| 7 | 4 |
| 8 | 2 |
| 9 | 4 |
How it's worked out
Most calculators store a number as a 64-bit double. MDN gives the limit: a double holds every whole number up to 9,007,199,254,740,991, which is . Past that it skips some, so 9,007,199,254,740,992 + 1 comes back unchanged. This page keeps each number as a list of digits, so the sum is 9,007,199,254,740,993.
Add, subtract and multiply carry digits by hand, as on paper, just with no limit on length.
Divide and mod give a remainder r with . So −17 divided by 5 gives a quotient of −4 and a remainder of 3, and −17 mod 5 is 3.
GCD uses the Euclidean algorithm: swap in the remainder until it is 0. LCM divides by the GCD first, so the working numbers stay small.
Power multiplies by repeated squaring, with results capped at 50,000 digits. Modular power squares once for each binary digit of the exponent and reduces after every step, so an exponent with hundreds of digits is fine. Factorial runs up to 5,000 factorial, and integer square root gives the largest whole r with .
Each answer is checked by a second route. A product is divided back by B. A power is tested by casting out nines. A factorial has one trailing zero for each factor of 5, which is Legendre's count.
Worked examples
Priya finds where her spreadsheet goes wrong
Priya is testing IDs that pass through JavaScript. She adds 1 to 9,007,199,254,740,992, which is . Here the sum is 9,007,199,254,740,993, and the check takes 1 back off to get the start again.
A double cannot hold 9,007,199,254,740,993, since it needs 54 bits and a double keeps 53. So her code rounds it to 9,007,199,254,740,992. She stores the IDs as text or as BigInt instead.
Marco counts the zeros at the end of 100 factorial
For a puzzle, Marco wants the trailing zeros of . The result has 158 digits and begins 933262154439. It ends in 24 zeros.
The check counts factors of 5: 20 + 4 = 24. Each 5 pairs with a 2 to make a 10, and 2s are far more common, so the 5s set the count. The extra 4 come from 25, 50, 75 and 100, which hold two 5s each.
Lena checks a modular power from a cryptography class
Lena needs mod 1,000,000,007. The full power would run to tens of thousands of digits, but reducing after each squaring gives 95,353,359 at once. The exponent 65537 is , which has 17 binary digits, so it takes 17 squarings.
The check works the half power, mod 1,000,000,007 = 14,134,088. Squaring that and multiplying by 7 once more, mod 1,000,000,007, gives 95,353,359 again.
Reading your result
The short form and every digit. A long answer shows first in scientific form, with 4, 6, 10 or 15 significant figures. The full value is always there too. The product of the two 30-digit defaults has 60 digits and 197 bits.
The two size limits. "Exact in a double" asks if the result is at most . "Fits a signed 64-bit integer" asks if it is between and , the range of a long in Java or an int64 in C. The largest that fits is 9,223,372,036,854,775,807, and one more does not.
The prime test. It runs Miller-Rabin with the first 13 primes as bases. OEIS A014233 lists the smallest number that fools each set of bases, and with 13 bases that is 3,317,044,064,679,887,385,961,981. Below it, a pass is a proof. Above it, a pass is called a probable prime, while a fail always proves the number composite. With only 12 bases, 318,665,857,834,031,151,167,461 would slip through; here it is reported as composite.
Digit sum. A number is divisible by 9 when its digit sum is, and by 3 the same way. The digits of add to 88, which leaves 7 after dividing by 9, so is not a multiple of 3. The digit chart shows how often each digit appears, which is a quick way to spot a pattern such as the long run of zeros at the end of a factorial.
Common mistakes
- Trusting the last digits from a phone or a spreadsheet. Past 15 or 16 significant digits, a double rounds. The leading digits look right, which hides the error.
- Expecting −17 mod 5 to be −2. The % sign in C, Java and JavaScript keeps the sign of A, so it gives −2. Number theory, and this page, use the residue from 0 to B − 1, which is 3.
- Typing 1e9 or 2.5. Exponent notation and decimals are refused rather than rounded. Type 1000000000, or work out a power with the Power operation.
- Reading a probable prime as proven. Above the bound in OEIS A014233 a pass is strong evidence, not a proof. A result over 300 digits is not tested at all.
- Building a huge power to take a remainder. mod C does not need . Use Modular power: 2 to the power 1,000,000,006, mod 1,000,000,007, comes out as 1 straight away.