SUM1HARD - Summation of Multiples (hard)

no tags 

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 3+5+6+9=23.

Now you are given an integer N and an array of length K. You have to find the sum of all numbers that are multiples of at least one array's elements and below N.

Input

line1: K (1 <= K <= 15), N (1 <= N <= 109)

line2: K space-separated integers, the elements of the array, all elements of the array is between 1 and 100 inclusive.

Note: the least common multiple of all elements will not be bigger than 1018.

Output

One integer, the answer to the problem.

Example

Input:
2 10
3 5

Output:
23

hide comments
wisfaq: 2015-01-27 17:00:37

The problem SUM1 was kept in classical because of the surprisingly large number of WA's and TLE's for such an easy problem.
Of course that one is in fact a real tutorial problem if there is one. If you look up the English Wikipedia page for Project Euler you will see why.


RE: also there's surprisingly large number of AC for a new problem about 150 :)

Last edit: 2013-05-14 10:19:46
Francky: 2015-01-27 17:00:33

This is not a hard problem.
There's yet : EASYMATH.
Moved to tutorial.

RE: EASYMATH is a totally different problem , furthermore I think is not harder than mine.

and what the logic behind moving my harder version to tutorial and the easy one is on classical?
--ans(francky)--> I recommend you to trust in our work, and try to solve more problems here, you will understand better what is the difference between classical and other problems.

Last edit: 2013-05-14 09:18:23

Added by:Hasan Jaddouh
Date:2013-05-14
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:hard version of http://www.spoj.com/problems/SUM1/