+1 vote

This sounds like a homework and as such, the main goal here is to learn something. So providing you the full solution is actually worse than not helping.

I'd suggest looking up some Python tutorial and reference pages, such as https://www.w3schools.com/python/.

There, you can see the syntax and what functionality is available for you.

To solve the problem, you'd need to do the following steps in your code:

- iterate through the array (arr) that holds the input numbers
- calculate the GCD for all number pair (k and the actually iterated arr element -- arr[i])
- Add this calculated GCD to a counter (e.g. sum)
- keep repeating 1-3 until reaching the end of arr.
- display the result.

For calculating the GCD there could be various solutions. One of the naive solutions could be this:

- loop through integral numbers (backwards) starting from smaller of
*k*or*arr[i]*(*min(k, arr[i])*) until you reach 1. Let's call this*x*for this example. - Try dividing both
*k*and*arr[i]*with the currently iterated number (*x*) and check for the reminder. The operator for this is % (modulus). E.g.: reminder = k % x - If the result of modulus with
*x*for both*k*and*arr[i]*is 0, then you have a divisor. Since we're going from the largest number toward the smallest, we can be assured we have the greatest common divisor.

Of course, one can optimise this logic or come up with better ones, but this should work for now. You can improve it later, when the program works fine for the generic cases.

After you've done your implementation and have some problem, please, share your code so people can point out if you made any mistakes.

Good luck.

...