backupkid's blog

By backupkid, history, 4 hours ago, In English

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:

$$$ a \cdot x \equiv 0 \pmod b $$$
$$$ b \cdot x \equiv 0 \pmod c $$$
$$$ c \cdot x \equiv 0 \pmod a $$$

---

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 :)

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
3 hours ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

In the example, I think you mistakenly wrote input again, pls fix it.

  • »
    »
    3 hours ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    ahh okay , my bad !!

»
3 hours ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by backupkid (previous revision, new revision, compare).

»
3 hours ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

I'm not sure but I think answer is lcm(lcm(lcm(a,b),lcm(b,c)),lcm(c,a))

  • »
    »
    2 hours ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    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$$$.

    • »
      »
      »
      45 minutes ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      Yes, you are right. I was just in a hurry, so I wrote the first thing that came to mind.

»
116 minutes ago, hide # |
Rev. 6  
Vote: I like it 0 Vote: I do not like it

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

CPP Implementation
»
72 minutes ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

After trying for a while and getting help from AI, I finally figured it out...

Answer
Explanation

This is my first time writing an explanation, so I am pretty sure there are some problems, feel free to call them out.