We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.

The way modular arithmatic works, you can take the mod of each component of the product before you calculate the product and get the same result as if you were to mod the poduct after multiplying. My code had something like:

Thanks for that explanation. I was wondering why my solution of doing it after the multiplication was not working. I figured it was overflow causing issues, but I didn't think to solve that like this.

It's because in this case you know B is already mod C, so you calculate (A mod C * B) mod C. In fact, mike's code started with 1, so it's actually ((1 * A) mod C * B) mod C

## Connecting Towns

You are viewing a single comment's thread. Return to all comments →

Pretty annoying, not really a mathematics challenge, but rather a "know-how-to-deal-with-long-integers" challenge.

The way modular arithmatic works, you can take the mod of each component of the product before you calculate the product and get the same result as if you were to mod the poduct after multiplying. My code had something like:

Thanks for that explanation. I was wondering why my solution of doing it after the multiplication was not working. I figured it was overflow causing issues, but I didn't think to solve that like this.

why 1234567 why not the other number be taken?

"Output Format Total number of routes from T1 to Tn modulo

1234567"The problem says to output mod 1234567. That is where that number comes from.

shouldn't there be product = product%123456 after the loop.

I have studied (A * B) mod C = (A mod C * B mod C)

mod CIt's because in this case you know B is already mod C, so you calculate (A mod C * B) mod C. In fact, mike's code started with 1, so it's actually ((1 * A) mod C * B) mod C

i like the post, thanks for href test click here to go

https://www.google.com/

[url=https://www.google.com/] click to go [/url]

www.google.com

i like the post, thanks for sharing..