Advertisement
kdzhr

1011

Mar 17th, 2020
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. // OK 1011 Timus https://acm.timus.ru/problem.aspx?space=1&num=1011
  2.  
  3. # include <iostream>
  4. # include <cmath>
  5. int main() {
  6.     double p, q;
  7.     std::ios_base::sync_with_stdio(false);
  8.     std::cin >> p >> q;
  9.     size_t p_int = p * 1000;
  10.     if (p_int % 10 == 9) {
  11.         p_int++;
  12.     }
  13.     size_t q_int = q * 1000;
  14.     if (q_int % 10 == 9) {
  15.         q_int++;
  16.     }
  17.     size_t i = 0;
  18.     while (++i > 0) {
  19.         for (auto j = std::max(static_cast<int32_t>(p * i / 1000) - 2, 0); j <= i; j++) {
  20.             if (j * 100'000 > i * p_int && j * 100'000 < i * q_int) {
  21.                 std::cout << i << '\n';
  22.                 return 0;
  23.             } else if (j * 100'000 > i * q_int) {
  24.                break;
  25.            }
  26.        }
  27.    }
  28.    return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement