title: How to find common prime factors of two given numbers in C?
body: <p>I am trying to solve this problem:</p>
  <p>Input: the first line contains an integer <code>T</code> which represents the total cases you need to solve. Each test case contains <code>P</code> and <code>Q</code>, separated by space, represent the number you need to work on.</p>
  <p>Output: print the result which is calculated from the multiplication of <code>P</code> and <code>Q</code>’s minimum factor and maximum prime factor.</p>
  <p>Constraints: <strong>1 ≤  ≤ 100</strong> and <strong>2 ≤ , ≤ 1000000</strong></p>
  <p>Sample Input: <code>2 210 84 6 12</code><br>
  Sample Output:</p>
  <pre><code>Case #1: 14 
  Case #2: 6 
  </code></pre>
  <p>Explanation: Let’s take an example from the first case. The numbers 210 and 84 have several identical prime factors which are 2, 3, and 7. Number ‘2’ is the smallest common prime factor of the numbers, meanwhile number ‘7’ is their largest common prime factor. So, the result must be the multiplication of 2 and 7, which is 14.</p>
  <p>Here's my code that I've been working, I tried to find factors from the given number the store the factors into array then check for the prime, but I feel that this isn't the right algorithm :(</p>
  <pre><code>void factor(int num1) {
      int arrA[100000], a = 0, flag = 1;
      //check factor
      for (int i = 2; i &lt;= num1; i++) {
          if (num1 % i == 0) {
              arrA[a] = i;
              a++;
          }
      }
      // check prime
      for (int i = 0; i &lt; a; i++) {
          for (int j = 2; j &lt; a; j++) {
              if ((arrA[i] % j) == 0) {
                  flag = 0;
              }
          }
          if (flag == 1) {
              printf(&quot;%d &quot;, arrA[i]);
          }
          flag = 1;
      }
      printf(&quot;\n&quot;);
  }
  </code></pre>