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.
若存在三个环的周长分别是A, B, C,对A、B、C求公约数P,在环A,B,C分别走了i、j、k圈的情况下,走的总距离为i*A + j * B + k * C = P * l 。这里面i, j, k, l都是变量,必定可以调整 i、j、k、 l 的值使 l = n * m + 1,这时 i*A + j * B + k * C = (p * l) % m = p ,每重复一次该(i, j, k, l)数值组合的循环,余数能得到最小的增长p。所以,从点 S 到点 R ,只需求找出其中一条路径的距离,然后让余数按p增长,终能达到最大的余数值。
Find rings, get circumferences value of rings, than calculate common divisor for them.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Longest Mod Path
You are viewing a single comment's thread. Return to all comments →
若存在三个环的周长分别是A, B, C,对A、B、C求公约数P,在环A,B,C分别走了i、j、k圈的情况下,走的总距离为i*A + j * B + k * C = P * l 。这里面i, j, k, l都是变量,必定可以调整 i、j、k、 l 的值使 l = n * m + 1,这时 i*A + j * B + k * C = (p * l) % m = p ,每重复一次该(i, j, k, l)数值组合的循环,余数能得到最小的增长p。所以,从点 S 到点 R ,只需求找出其中一条路径的距离,然后让余数按p增长,终能达到最大的余数值。
Find rings, get circumferences value of rings, than calculate common divisor for them.