Hi everyone!
I recently came across this problem and I’m not sure how to approach it efficiently. Any hints or ideas would be appreciated!
Problem Statement
Cyclic Divisibility
Given three positive integers $$$a, b, c$$$, we need to find the smallest positive integer $$$x$$$ such that:
---
Input
The first line contains an integer $$$T$$$ — the number of test cases ($$$1 \le T \le 10^5$$$).
Each of the next $$$T$$$ lines contains three integers $$$a, b, c$$$ ($$$1 \le a, b, c \le 10^6$$$).
Output
For each test case, print a single integer — the minimum value of $$$x$$$ satisfying the conditions.
Example
Input
2
4 6 10
12 34 56
Output
30
1428
Thanks for reading!
Any ideas or hints would be appreciated :)









In the example, I think you mistakenly wrote input again, pls fix it.
ahh okay , my bad !!
Auto comment: topic has been updated by backupkid (previous revision, new revision, compare).
I'm not sure but I think answer is lcm(lcm(lcm(a,b),lcm(b,c)),lcm(c,a))
This can be simplified to $$$\text{lcm}(a, \text{lcm}(b,c))$$$ since being a multiple of $$$b$$$ and $$$c$$$ implies being a multiple of $$$b,c$$$.
Yes, you are right. I was just in a hurry, so I wrote the first thing that came to mind.
We know that $$$b$$$ divides $$$ax$$$. Consider $$$d_1 = gcd(a,b)$$$.
Therefore $$$a=d_1\cdot a_1$$$ and $$$b=d_1\cdot b_1$$$. Also $$$gcd(a_1,b_1)=1$$$. We can prove that $$$gcd(a_1,b_1)=1$$$ by considering $$$gcd(a_1,b_1)=k$$$ and $$$k \gt 1$$$
Now this means that $$$k$$$ divides both of $$$a_1$$$ and $$$b_1$$$ and therfore leading to greater i.e. $$$gcd(a,b) \gt d_1$$$
Continuing we get that $$$b_1$$$ divides $$$a_{1}x$$$. Obiviously $$$b_1$$$ will divide $$$x$$$ because of our first condition.
This means $$$\frac{b}{gcd(a,b)}$$$ divides $$$x$$$.
This can be done for each of the system of modular equations.
Our final answer is just take $$$LCM$$$ over all of these
thanks for ur help !
After trying for a while and getting help from AI, I finally figured it out...
$$$ x = lcm(\frac{b}{gcd(a, b)}, \frac{c}{gcd(b, c)},\frac{a}{gcd(a, c)}) $$$
First consider the following statements: \begin{align} ax \equiv 0 \pmod b \end{align} \begin{align} bx \equiv 0 \pmod c \end{align} \begin{align} cx \equiv 0 \pmod a \end{align}
This means that $$$b$$$ is a multiple of $$$ax$$$, $$$c$$$ is a multiple of $$$bx$$$ and $$$a$$$ is a multiple of $$$cx$$$. We can write it as:
\begin{align} ax \mid b \end{align} \begin{align} bx \mid c \end{align} \begin{align} cx \mid a \end{align}
($$$ a \mid b $$$ means $$$a$$$ divides $$$b$$$)
There is a known property in number theory: \begin{align} m \mid nx \qquad \Longleftrightarrow \qquad \frac{m}{\gcd(m,n)} \mid x \end{align}
Hence above expressions can be simplified as: \begin{align} \frac{b}{gcd(a, b)} \mid x \end{align} \begin{align} \frac{c}{gcd(b, c)} \mid x \end{align} \begin{align} \frac{a}{gcd(c, a)} \mid x \end{align}
The expression basically tells what $$$x$$$ must contribute (in prime factors term) to make b divisible by $$$ax$$$. Let: \begin{align} d_1 = \frac{b}{gcd(a, b)} \end{align} \begin{align} d_2 = \frac{c}{gcd(b, c)} \end{align} \begin{align} d_3 = \frac{a}{gcd(c, a)} \end{align} Then we get: \begin{align} d_1 \mid x , \qquad d_2 \mid x , \qquad d_3 \mid x \end{align}
Which basically means that $$$x$$$ is multiple of all $$$d_1, d_2, and\; d_3$$$. Since we are looking for smallest value, we are looking for smallest such $$$x$$$ that is still a multiple of $$$d_1, d_2, and\; d_3$$$. Now by definition: \begin{align} LCM(a,b,c) = Smallest/Least\;common\;multiple\;of\;a,\;b\;and\;c \end{align}
Hence we arrive to the answer of: \begin{align} x = lcm(\frac{b}{gcd(a, b)}, \frac{c}{gcd(b, c)},\frac{a}{gcd(a, c)}) \end{align}
This is my first time writing an explanation, so I am pretty sure there are some problems, feel free to call them out.
thanks