#Lutece1165. ModModMod (Hard Ver.)
ModModMod (Hard Ver.)
Migrated from Lutece 1165 Problem 300 in TCO Round 2A(Changed Version)
All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.
Description
Moose Mod has just learned about the mod operator.Given two positive integers x and y, the mod operator returns the remainder when x is divided by y.For example, 17 mod 5 = 2 because 17 = 3*5 + 2.
Moose Mod has just defined a function that applies a sequence of N mod operators to its input. Formally, the function looks as follows: f(x) = (((x mod m[0]) mod m[1]) ... mod m[N-1]). For example, m = { 10, 3 } corresponds to the function f(x) = (x mod 10) mod 3. For this function we have f(18) = (18 mod 10) mod 3 = 8 mod 3 = 2.
You are given integers.You are also given a int .Moose Mod is interested in finding the sum f(1) + f(2) + ... + f(R).Compute and output its value.
Input
The first line of the input contains two integers and , means the integer describe above and means the number of mods.
The second line of the input contains integers.The ith integer means the ith mod.
Output
Print the answer in a single line
Samples
3 10
5 3 2
4
Resources
2015 UESTC ACM Training for Math