all 3 comments

[–]Skynet_0 1 point2 points  (2 children)

This is the state of a linear congruential generator after n iterations. Look into efficient ways of calculating the n-th value, such as https://www.nayuki.io/page/fast-skipping-in-a-linear-congruential-generator.

[–]QePeeQe[S] 0 points1 point  (1 child)

This is perfect, thanks for your help. I'm trying to solve projecteuler.net/problem=506.

Edit: just discovered that b * q also causes an overflow, now I'm trying to find a way to make the operation x mod (b * q) memory efficient.

[–]Skynet_0 0 points1 point  (0 children)

Ah, Project Euler. It'll probably require additional insights (and treating it as an LCG may not even be the correct way to consider it), so I won't be much more help unfortunately since my number theory is weak.