fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. void solve() {
  9. long long n;
  10. if (!(cin >> n)) return;
  11.  
  12. string s = to_string(n);
  13. int len = s.length();
  14.  
  15. for (int l = max(1, len - 1); l <= len; ++l) {
  16. int half = (l + 1) / 2;
  17. long long base = 1;
  18. for (int i = 0; i < half - 1; ++i) base *= 10;
  19.  
  20. long long start = base;
  21. long long end = base * 10 - 1;
  22.  
  23. if (l == len) {
  24. end = stoll(s.substr(0, half));
  25. }
  26.  
  27. for (long long first_half = end; first_half >= start && first_half >= end - 2000; --first_half) {
  28. string s_half = to_string(first_half);
  29. string a_str = s_half;
  30. for (int i = l / 2 - 1; i >= 0; --i) {
  31. a_str += s_half[i];
  32. }
  33.  
  34. long long a = stoll(a_str);
  35. if (a <= n && (n - a) % 12 == 0) {
  36. cout << a << " " << n - a << "\n";
  37. return;
  38. }
  39. }
  40. }
  41. cout << -1 << "\n";
  42. }
  43.  
  44. int main() {
  45. ios_base::sync_with_stdio(false);
  46. cin.tie(NULL);
  47. int t;
  48. if (cin >> t) {
  49. while (t--) {
  50. solve();
  51. }
  52. }
  53. return 0;
  54. }
Success #stdin #stdout 0.01s 5308KB
stdin
6
1
10
310
12
1000000000
6111111111111111
stdout
1 0
-1
22 288
-1
-1
999999999999999 5111111111111112