Problem
Given thehead of a linked list, return the list after inserting the greatest common divisor of each pair of adjacent nodes.
Between every pair of adjacent nodes, insert a new node with a value equal to the greatest common divisor of them.
The greatest common divisor of two numbers is the largest positive integer that evenly divides both numbers.
Examples
Constraints
- The number of nodes in the list is in the range
[1, 5000]. 1 <= Node.val <= 1000