Codeforces Round 340 (Div. 2) - 617 A. Elephant solution
I tried to solve it via ceil() funtion in math.h but it gave errors.
The easiest way to get the least amount of steps is to have the largest number, 5 here, as many times as possible. And then you cover the remaining part with other numbers once. For instance, let's assume input is 14; you need two 5 and one 4; or 27, you need five 5 and one 2; and so on.
If entered number is divisible by 5, meaning mod 5 is 0, then just divide it by 5 to get the number of the steps. If its mod 5 is not equal to 0 then divide the number by 5 and 1 so as to floor it up, or ceil up, or round up.
I wish we could use ceil() function.
Write your comments below.
Thanks. Good luck!
- #include <stdio.h>
- #include <math.h>
- int main() {
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- int a;
- scanf("%d", &a);
- if(a%5!=0) printf("%d\n", a/5+1);
- else printf("%d\n", a/5);
- return 0;
- }
No comments:
Post a Comment