fork download
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. long long x, y;
  6. long long ex;
  7. bool check(int mid) {
  8. long long res = (y + mid) * 100 / (x + mid);
  9.  
  10. if(ex != res) return true;
  11. else return false;
  12. }
  13.  
  14. long long solve() {
  15. long long start = 0;
  16. long long end = 1000000000;
  17. long long mid;
  18.  
  19. if(!check(end)) return -1;
  20.  
  21. while(start + 1 < end) {
  22. mid = (start + end) / 2;
  23.  
  24. if(check(mid)) end = mid;
  25. else start = mid;
  26. }
  27.  
  28. return end;
  29. }
  30.  
  31. int main() {
  32. ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  33.  
  34. cin >> x >> y;
  35. ex = y * 100 / x;
  36.  
  37. cout << solve();
  38. }
Success #stdin #stdout 0.01s 5284KB
stdin
300 299
stdout
-1