#C10761. Common Prime Factors Based on GCD

    ID: 40002 Type: Default 1000ms 256MiB

Common Prime Factors Based on GCD

Common Prime Factors Based on GCD

You are given two positive integers for each test case. Your task is to find their common prime factors using the Euclidean algorithm.

Specifically, if we denote the greatest common divisor by \(\gcd(a, b)\), then you should find all prime numbers \(p\) such that \(p\) divides \(\gcd(a,b)\). The output should be these prime factors sorted in ascending order and separated by a space. If there are no prime factors (i.e. when \(\gcd(a,b)=1\)), print None.

Example:

  • For inputs 28 and 35, \(\gcd(28,35)=7\) and the only prime factor is 7.
  • For inputs 15 and 25, \(\gcd(15,25)=5\) and the only prime factor is 5.

inputFormat

The first line of input contains an integer \(T\) representing the number of test cases. Each of the next \(T\) lines contains two space-separated positive integers \(a\) and \(b\).

outputFormat

For each test case, output a single line containing the common prime factors of \(a\) and \(b\) (obtained from \(\gcd(a,b)\)). The factors must be printed in ascending order, separated by a space. If no common prime factors exist, output None.

## sample
4
28 35
15 25
100 10
17 19
7

5 2 5 None

</p>