Advertisement
savrasov

log

May 19th, 2017
391
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. int a[2000], b[2000], h;
  2.  
  3. bool check()
  4. {
  5.     for (int i = 1000; i > -1; i--)
  6.         if (a[i] && !b[i]) return 1;
  7.         else if (!a[i] && b[i]) return 0;
  8.         else if (a[i] && b[i] && a[i] != b[i]) return b[i] < a[i];
  9.     return 1;
  10. }
  11.  
  12. void umn(int t)
  13. {
  14.     int c = 0, p;
  15.     for (int i = 0; i < 1000; i++)
  16.         p = b[i] * t + c, b[i] = p % 10, c = p / 10;
  17. }
  18.  
  19. int main()
  20. {
  21.     ios_base::sync_with_stdio(0);
  22.     string s;
  23.     int r, ans = 1;
  24.     cin >> s >> r;
  25.     for (int i = 0; i < s.size(); i++) a[s.size() - i - 1] = s[i] - '0';
  26.     for (int r1 = r; r1; r1 /= 10) b[h++] = r % 10;
  27.     while (check())
  28.         umn(r), ans++;
  29.     cout << ans - 1;
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement