1
\$\begingroup\$

Challenge

HP is doing research in mathematics . After doing lots of research, she struck in a problem . She found four numbers n,a, b and c .Now, She wants to know how many number exists which are less than or equal to n and are divisible by a ,b or c .

Input :

4 integers denoting n,a,b and c separated by space

Output :

intger which denotes the count of the numbers which are divisible a,b,c

Scoring:

This is , shortest code in bytes wins.

\$\endgroup\$
  • 5
    \$\begingroup\$ Can you add test cases? Does the count include 0 and negative numbers? \$\endgroup\$ – fireflame241 Jul 24 '17 at 4:25
  • 3
    \$\begingroup\$ What are the ranges of the input parameters? \$\endgroup\$ – Peter Taylor Jul 24 '17 at 8:11
0
\$\begingroup\$

Python 2, 72 65 bytes

Note: This solution works for positive integers:

lambda a,b,c,n:len([x for x in range(1,n+1)if x%a*(x%b)*(x%c)<1])

Try it online!

|improve this answer|||||
\$\endgroup\$
0
\$\begingroup\$

Python 2, 52 bytes

lambda n,a,b,c:n/a+n/b+n/c-n/a/b-n/a/c-n/b/c+n/a/b/c

Try it online!

By the inclusion–exclusion principle.

|improve this answer|||||
\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.