fork download
  1.  
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. int t, b, c, k;
  5. int x(int a)
  6. {
  7. int r = 10;
  8. while (a >= r)
  9. r*= 10;
  10. return r;
  11. }
  12. string a(int b, int c, int k)
  13. {
  14. string s = "";
  15. int nho = 0, r, d = x(c);
  16. while (s.size() <= 1000)
  17. {
  18. r = c % 10 * k + nho % 10;
  19. s = to_string(r%10) + s;
  20. c = ((r%10) * d + c) / 10;
  21. nho = nho/10 + r/10;
  22. if (c*k + nho == b) return s;
  23. }
  24. return "-1";
  25. }
  26. int main()
  27. {
  28. cin>>t;
  29.  
  30. while (t--)
  31. {
  32. cin>>b>>c>>k;
  33. cout<<a(b, c, k)<<'\n';
  34. }
  35. }
Success #stdin #stdout 0s 5312KB
stdin
Standard input is empty
stdout
Standard output is empty