ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1131. Copying

WA10, help me please)
Posted by Roman Hrynevych 21 Jan 2020 01:34
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main() {

   int n, k;

   scanf("%d %d", &n, &k);

   if (n < 1 || n > pow(10, 9) || k < 1 || k > pow(10, 9)) {
      return 0;
   }

   unsigned long long result = 0;
   unsigned long long buffer = 1;
   n--;

   for (int i = 0; n >= 0; i++) {

      n -= buffer;
      result++;
      buffer *= 2;

      if (n <= 0) {
         printf("%llu\n", result);
         return 0;
      }

      if (buffer >= k) {
         buffer = k;
         double count = (double)n / buffer;
         if (count != (long long)count) {
            count++;
         }
         result += count;
         printf("%llu\n", result);
         return 0;
      }
   }
   return 0;
}

Edited by author 21.01.2020 01:57
Re: WA10, help me please)
Posted by Kin 1 Sep 2021 15:18
Test 10 is n = 1