Sunday, March 12, 2023

Codeforces Round 340 (Div. 2) - 617 A. Elephant solution

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! 

  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main() {
  5. #ifndef ONLINE_JUDGE
  6. freopen("input.txt", "r", stdin);
  7. freopen("output.txt", "w", stdout);
  8. #endif
  9. int a;
  10. scanf("%d", &a);
  11. if(a%5!=0) printf("%d\n", a/5+1);
  12. else printf("%d\n", a/5);
  13. return 0;

No comments:

Post a Comment