Under construction

Still being built. Things may change

Sum of Multiples

Interview

Time limit1sMemory limit512 MB

Summary
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 NN and MM positive integers KiK_i. Find the sum of all integers between 11 and NN inclusive that are multiples of at least one of the KiK_i.

Input

The first line contains NN and MM. (2≤N≤10002 \le N \le 1000, 1≤M<N1 \le M < N)

The next line contains MM integers KiK_i. (2≤Ki≤10002 \le K_i \le 1000)

No two KiK_i are equal, and they are given in ascending order.

Output

Print the sum of the multiples.

Examples2

  1. Example 1

    Input
    10 2
    2 3
    
    Expected output
    42
    
  2. Example 2

    Input
    1000 3
    3 5 7
    
    Expected output
    272066