Can anyone give me a hint to solve this problem https://codeforces.com/contest/1152/problem/C please? Thank you

# | User | Rating |
---|---|---|

1 | tourist | 3557 |

2 | Radewoosh | 3468 |

3 | Um_nik | 3429 |

4 | Petr | 3354 |

5 | Benq | 3286 |

6 | mnbvmar | 3280 |

7 | wxhtxdy | 3276 |

7 | LHiC | 3276 |

9 | ecnerwala | 3214 |

10 | yutaka1999 | 3190 |

# | User | Contrib. |
---|---|---|

1 | Errichto | 191 |

2 | Radewoosh | 180 |

3 | tourist | 173 |

4 | Vovuh | 165 |

4 | antontrygubO_o | 165 |

6 | PikMike | 164 |

7 | rng_58 | 160 |

8 | Um_nik | 156 |

8 | majk | 156 |

10 | 300iq | 154 |

Can anyone give me a hint to solve this problem https://codeforces.com/contest/1152/problem/C please? Thank you

↑

↓

Codeforces (c) Copyright 2010-2019 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Oct/20/2019 15:49:24 (h1).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|

try to make gcd as large as possible; gcd(a,b)=gcd(b-a,a)

During the contest I too thought that making the gcd as large as possible might be optimal but we have to minimise the lcm which is equal to product of 2 numbers divided by the gcd. How does maximising the gcd ensures minimum lcm. What is the mathematical proof for this

yes, this was my question as well, how to guarantee that by maximizing the gcd , the lcm will be minimized and also how to know that gcd(8+k, 12+k) = 4 for example is as maximum as possible when k = 0.

hint 1let's suppose $$$a \leq b$$$, then $$$\gcd{(a + k, b + k)} = \gcd{(a + k, b - a)}$$$

hint 2$$$\gcd{(a + k, b - a)}$$$ is a divisor of $$$b - a$$$

hint 3for each $$$d$$$, divisor of $$$b - a$$$, we are trying to find such k that $$$\gcd{(a + k, b - a)} = d$$$

one more hint?

is a divisor ofd+a, so there is a integerkthatn+a=k*n. Therefore,d=k*n—d. We also wantato be as small as possible, sokshould be as small as possible.n