Gears

Description

We designed this problem so that it's easy to create inputs and to check an output on our side, but it's hard on the teams' side.

We simply placed some gears on a grid, then calculated the rotation speed of the last gear and didn't think about how hard it is to find a proper configuration for that speed. Our very brute force solver could solve only three inputs (in reasonable time).

To properly solve the problem a branch and bound backtracking can be used. The bounding part (checking if some configuration of gears cannot lead to a solution) is hard. The solution also requires big integer arithmetics and factorizations.

Given a rotating gear with radius R0 and rotation speed V0, after a chain of N connected gears on the same level, the speed of the last one is VN = (-1)N R0/RN V0. So only the number of gears and the ratio between the radiuses of the first and last gears matter.

If at some point there is a level change, where a gear with radius RA is connected to a rotating source and a gear with RB on the same rod transmits the rotation onward, then the formula for the speed is VN = (-1)N (R0 RB)/(RA RN) V0. So it's only modified by an RB/RA factor.

The prime factors of the numerator and denominator of the required speed can be used while enumerating the possible gear configurations.

Our solution to 7.in:

gears 7.in solution