Fastest way to solve the divisibility of numbers : <p>I have a program in which in which 4 numbers are input n,a,b,c</p>

<p>how many number exists which are less than or equal to n and are divisible by a ,b or c .</p>

<p>Sample input case - 
15 2 3 5
output 
11</p>

<p>Here n = 15 , a= 2, b=3,c = 5 The number which are divisible by a ,b, or c are 2,3,4,5,6,8,9,10,12,14,15 i.e 11 numbers , so output is 11</p>

<p>I have tried with this solution but the time is exceeding</p>

<pre><code>#include&lt;stdio.h&gt;

long long divisibilty (long long a, long long c, long long b, long long n ) {
    long long temp, min,count = 0,i;
    temp = (a &lt; b)    ? a : b;
    min =  (c &lt; temp) ? c : temp;

    for(i=min;i&lt;=n;i++){
        if( (i % a == 0)  || (i % b == 0) || (i % c == 0) ){
            count++;
        }
    }
    return count;

}

int main() {

    int t_i;

        long long n;
        scanf("%lld", &amp;n);
        long long a;
        scanf("%lld", &amp;a);
        long long b;
        scanf("%lld", &amp;b);
        long long c;
        scanf("%lld", &amp;c);

        long long out_ = divisibilty(a, c, b, n);
        printf("%lld", out_);

}
</code></pre>

<p>Can anyone help me with a better solution</p>
