SUM1HARD - Summation of Multiples (hard)
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.
|
|
Francky:
2015-01-27 17:00:33
This is not a hard problem.
|
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/ |