# How many times, are they multiples?

You are given three parameters: start(int), end(int) and list(of int);

Make a function that returns the amount of times all the numbers between start and end are multiples of the elements in the list. example:

start = 15; end = 18; list = [2, 4, 3];
15 => 1 (is multiple of 3)
16 => 2 (is multiple of 2 and 4)
17 => 0
18 => 2 (is multiple of 2 and 3)
result = 5

The function should accept two positive integer numbers and an array of integers as parameters, returning the total integer number. Assume that start is less <= end.

examples:

Multiple(1, 10, [1, 2]); => 15
Multiple(1, 800, [7, 8]); => 214
Multiple(301, 5000,[13, 5]); => 1301

The shortest solution is the victor!!! May he odds be ever in your favor...

New contributor
Rui Silva is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
• Nice challenge! Presumably the winning criterion is shortest code? In which case you should say so explicitly, and add the code-golf tag. – Robin Ryder Dec 2 at 10:16
• Can we assume that start will always be less than end? – Galen Ivanov Dec 2 at 11:49
• You say integers. So start, end or the elements in list may be non-positive? – Seb Dec 3 at 11:17
• Thanks for the feedback, I was lacking that in the problem. – Rui Silva Dec 3 at 14:43
• I'd like to ask a question (as I'm really new in this channel), how do I decide the winner? since each language has it's own limitations... Or is it simply a personal preference? – Rui Silva 8 hours ago

# 05AB1E, 5 bytes

ŸÑ˜åO

Try it online!

### Explanation

Ÿ       - the numbers between start and end
Ñ      - get their divisors
˜     - deep flatten this list
å    - find the instances of the elements in the list in these divisors
O   - Sum this

# JavaScript (Node.js), 44 bytes

(a,x,y)=>a.map(n=>t+=y/n-(~-x/n|0)|0,t=0)&&t

Try it online!

# Python 2, 38 bytes

lambda a,x,y:sum(y/i-~-x/i for i in a)

Try it online!

$$\ \sum _{i \in list} \lfloor \frac{end}{i} \rfloor - \lfloor \frac{start-1}{i} \rfloor \$$

The answer seems trivial and naive. So am I misunderstand something?

• Your Python answer is right -- I was going to post the same. Congrats on figuring out the simplification. I'm disappointed nobody else had found the floor-division idea earlier, at least on my quick glance of the answers. – xnor Dec 3 at 9:50
• @xnor the formula comes up with my mind just after I read the question. But since the question is posted ~1d ago (and no one using it), I can't quite believe it could be correct. After posting the JavaScript version, I realized that by using Python I could save many bytes.. – tsh Dec 3 at 9:55

(a#b)x=sum[1|0<-mod<$>[a..b]<*>x] Try it online! Explanation: (a#b)x --take two values a and b and the list x [a..b] --generate the range a, a+1, ... , b mod<$>[a..b]      --partially apply "mod" to each entry of the list
mod<$>[a..b]<*>x --apply the partially applied functions to all values of the list x [1|0<-mod<$>[a..b]<*>x] --generate a new list with a one for every zero in the previously computed list

Try it online!

# C# (Visual C# Interactive Compiler), 54 bytes

(a,b,l)=>l.Where(x=>a%x<1).Count()+(++a>b?0:f(a,b,l));

Try it online!

Recursive approach

• It's recursive, but you don't define f. You should define it like this: f=(a,b,l)=>... – Olivier Grégoire Dec 2 at 22:39
• @OlivierGrégoire If it is recursive, you have to include the whole function definition: Func<int,int,IEnumerable<int>,int>f=(a,b,l)=>..., since f=(a,b,l)=>... is not a valid expression (f does not exist yet). However, it would just be shorter to do int f(int a,int b,IEnumerable<int>l)=>... – Embodiment of Ignorance Dec 3 at 4:12
• if you take in int[] instead of IEnumerable<int> you can use Length instead of Count(), removing 1 byte – Ivan García Topete 2 days ago

# SimpleTemplate, 86 bytes

Yeah, kinda long, but it works!
Receives 2 numbers (in any order) and an array/string of 1-digit numbers (e.g.: "243"), passed to the render() method of the compiler.

{@fori fromargv.0 toargv.1}{@eachargv.2}{@ifi is multiple_}{@incR}{@/}{@/}{@/}{@echoR}

Displays the result or nothing, if none is

Ungolfed

{@set count 0}
{@for i from argv.0 to argv.1}
{@each argv.2 as number}
{@if i is multiple of number}
{@inc by 1 count}
{@/}
{@/}
{@/}
{@echo count}

Should be mostly straightforward.

Change line 986 to test the golfed and ungolfed versions, and line 988 to get the input.

## Mathematica, 52 bytes

f[s_,e_,l_]:=(q=Quotient;Total[q[e,#]-q[s-1,#]&/@l])

This uses the simplification formula from @tsh

A less clever solution at 66 bytes but more directly following the OP:

f[s_,e_,l_]:=Total[Length@Intersection[Divisors@#,l]&/@Range[s,e]]