Sum of Multiples
InterviewTime limit1sMemory limit512 MB
Given N and a list of divisors K_i, sum every integer from 1 to N that is divisible by at least one K_i, counting each qualifying number once.
- Level
Easy3 of 10
- Topics
- Implementation, Math, Brute force
- Solved
- No attempts yet
Problem
You are given a positive integer and positive integers . Find the sum of all integers between and inclusive that are multiples of at least one of the .
Input
The first line contains and . (, )
The next line contains integers . ()
No two are equal, and they are given in ascending order.
Output
Print the sum of the multiples.