1

I am making a program about the formula 10^(a-1)-1 mod a = 0. However, when using Javascript, it doesn't work with numbers for a above 23. Example:

var b = 29
var a = Math.pow(10, b-1)

console.log(a);
console.log(a/b);
console.log(a % b)

This is the output:

1e+28
3.448275862068965e+26
14

The output for the modulo function should be 1. Is there any way to make it solve the calculations correctly?

Boopiester
  • 141
  • 1
  • 10

1 Answers1

1

You can use BigInt.

var b = 29n;
var a = 10n ** (b - 1n);
console.log(a.toString());
console.log((a/b).toString());
console.log((a % b).toString());
Unmitigated
  • 76,500
  • 11
  • 62
  • 80