given a list of M numbers and a positive integers N, print the sum of numbers whose position in the list is divisible by N .consider that the position of numbers range from 1 to N
INPUT:
the first line contains two-spaced integers N, M
the second line contain M space-separated integers.
output:
print a single integer representing the required sum
explanation:
Sample Output1
Given N=1 , M=7
and the number list = [4,8,6,6,7,9,3]
As every position is divisible by 1,
4+8+6+6+7+9+3=43
so the output should be 43
N, M = input().split()
numbers = [int(n) for n in input().split()]
buff = 0
for i in range(int(M)):
if (i+1) % int(N) == 0:
buff += numbers[i]
print(buff)
Comments
Leave a comment