-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Closed
Labels
Description
Hello there,
I was attacking Project Euler, problem 26:
"Find the value of d <1000 for which 1/d contains the longest recurring cycle in its decimal fraction part."
I was trying to find the length of the repetend for each 1/d by calculating the smallest k for which 10ᵏ mod d == 1 but was getting weird/wrong results, e.g.
var mathjs = require('mathjs');
mathjs.config({
number: 'BigNumber',
precision: 4096
});
var p = mathjs.chain(10)
.pow(58)
.mod(531)
.done();
console.log(mathjs.format(p));
/*
Expected answer: 1
Actual answer: 0
*/
The expected answer is 1, per https://www.wolframalpha.com/input/?i=10%5E58+mod+531 but it's returning 0?
Reproduction with a more obviously wrong result:
(...)
var p = mathjs.chain(10)
.pow(16)
.mod(3)
.done();
console.log(mathjs.format(p));
/*
Expected answer: 1
Actual answer: 0
*/
The greatest power of 10 for which mod(3) gives the correct answer is 15.
Is there something I'm doing wrong here?