ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 2171. Two Progressions 2

Idea
Posted by InstouT94 8 Sep 2023 23:23
To solve the problem, you can use the inclusion-exclusion principle. The intersection of two arithmetic progressions can be found by solving the Diophantine equation. If the difference in the new progression is too large, you can replace it with n+1. It should be noted that the first element of the new progression must be no less than the first elements of the intersecting progressions. You should also consider possible type overflows. My implementation uses int128, but I think it is possible to solve it using int64.

Edited by author 15.07.2024 15:28