-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode2234B.cpp
More file actions
46 lines (35 loc) · 741 Bytes
/
Copy pathcode2234B.cpp
File metadata and controls
46 lines (35 loc) · 741 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
* Contest : Codeforces Round 1102 (Div. 2)
* Problem : B - Palindrome, Twelve and Two Terms
* Link : https://codeforces.com/contest/2234/problem/B
* Time : O(T * logN)
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fastio ios::sync_with_stdio(0); cin.tie(0);
bool isPalindrome(ll a) {
string num = to_string(a);
string rev = num;
reverse(rev.begin(), rev.end());
return num == rev;
}
void solve() {
ll n; cin >> n;
ll b = (n/12) * 12;
while (b >= 0) {
ll a = n-b;
if (isPalindrome(a)) {
cout << a << ' ' << b << '\n';
return;
}
b -= 12;
}
cout << "-1\n";
}
int main() {
fastio
int tc; cin >> tc;
while (tc--) solve();
return 0;
}