/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
 
class Solution {
public:
    int GCD(int num1, int num2)
    {
        if (num2 == 0)
            return num1;
        return GCD(num2, num1 % num2);
    }

    ListNode* insertGreatestCommonDivisors(ListNode* head)
    {
        ListNode* ptr = head;
        while(ptr->next != nullptr)
        {
            int a = ptr->val;
            int b = ptr->next->val;
            int c = GCD(a, b);
            
            /*** 1. Correct ***/
            ListNode* n = new ListNode(c);
            n->next = ptr->next;
            ptr->next = n;
            
            /*** 2. Wrong ***/
            ListNode n(c, ptr->next);
            ptr->next = &n;
            
            ptr = ptr->next->next;
        }
        return head;
    }
};