Блог пользователя backupkid

Автор backupkid, история, 3 часа назад, По-английски

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

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
2 часа назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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

  • »
    »
    114 минут назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    ahh okay , my bad !!

»
113 минут назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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

»
112 минут назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

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

»
51 минуту назад, скрыть # |
Rev. 6  
Проголосовать: нравится 0 Проголосовать: не нравится

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
»
7 минут назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

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.