NOOFCOKE - Editorial

PROBLEM LINK:

Practice
Contest : CodeShake

Author: Amruta Patil
Tester: Amruta Patil
Editorialist: Amruta Patil

DIFFICULTY:

CAKE WALK

PREREQUISITES:

Basic Math

PROBLEM:

Shannu had been to Goa in his summer holidays. Shannu has to walk a distance of M km to reach his place. As it was too hot Shannu decides to drink a coke after every N km from his start point. At the first N km he drinks 1 coke, at the second N km he drinks 2, at the third N km he drinks 3, he keeps on increasing his drink at every N km till he reaches his destination. How many cokes does he drink before he reaches his place?

QUICK EXPLANATION:

M and N is the input, where M is the distance in Km to reach Shannu’s place from start point and N the distance in km where he drinks coke.
At every N km from his start point he drinks the coke and the no of coke he drinks is increased by 1 at every N km, till he reaches his destination.

EXPLANATION:

Here Shannu is the person who has to walk M km to reach his place where he lives. On the way he decides to drink coke along the way at every N km from the point where he started to walk(i.e., from 0Km).
When he reaches the first N km he drinks 1 coke(where, N<M), for the second N km he drinks 2 coke(when, N+N<M), which means at 2N km he drank 1+2=3 coke. For the next N km he drinks 3, that is at 3N km he drank 1+2+3=6. He keeps increasing his drink at every N km till he reaches his place.

The first line input must contain M and N.
The output must be the total number of cokes that Shannu drinks.

SOLUTIONS:

Setter's Solution
#include <stdio.h>
int main()
{
    int m,n,sum=0,i;
    scanf("%d %d",&m,&n);
    for(i=0;i<(m/n);i++){
        sum=sum+(i+1);
    }
    printf("%d",sum);
    return 0;
}