Advertisement
GerONSo

Untitled

Nov 18th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. /*
  2. --┬-- | | --┬-- | |
  3. | |\ | | | |
  4. | | \ | | -----> | |
  5. | | \ | | | |
  6. | | \ | | | |
  7. --┴-- | \| | └---- └----
  8.  
  9. */
  10.  
  11. // #define pragma
  12.  
  13. #ifdef pragma
  14. #pragma GCC optimize("Ofast")
  15. #pragma GCC optimize("no-stack-protector")
  16. #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  17. #pragma GCC optimize("unroll-loops")
  18. #pragma GCC diagnostic ignored "-Wunused-result"
  19. #endif // pragma
  20.  
  21. #include<bits/stdc++.h>
  22. #include <ext/pb_ds/assoc_container.hpp>
  23. #include <ext/pb_ds/tree_policy.hpp>
  24.  
  25. #define ll long long
  26. #define all(x) begin(x), end(x)
  27. #define pb push_back
  28. #define x first
  29. #define y second
  30. #define int long long
  31. #define zero(x) memset(x, 0, sizeof(x))
  32.  
  33. using namespace std;
  34. using namespace __gnu_pbds;
  35.  
  36.  
  37. typedef vector<int> vi;
  38. typedef vector<bool> vb;
  39. typedef pair<int, int> pii;
  40. typedef long double ld;
  41. typedef vector<vi> matrix;
  42. typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
  43.  
  44. const int INF = 1e9 + 7;
  45. const int MAXN = 1e6 + 8;
  46. const ld EPS = 1e-9;
  47. const ld PI = atan2(0, -1);
  48.  
  49. void seriy() {
  50. ios::sync_with_stdio(0);
  51. cin.tie(0);
  52. cout.tie(0);
  53. // cout << fixed << setprecision(7);
  54. // cerr << fixed << setprecision(7);
  55. #if 0
  56. freopen("input", "r", stdin);
  57. freopen("output", "w", stdout);
  58. #endif
  59. }
  60.  
  61. bool pal(int n) {
  62. string s = "";
  63. while(n > 0) {
  64. s += (char)(n % 10 + '0');
  65. n /= 10;
  66. }
  67. bool f = 0;
  68. for(int i = 0; i < s.size(); i++) {
  69. if(s[i] != s[s.size() - i - 1]) {
  70. f = 1;
  71. }
  72. }
  73. return !f;
  74. }
  75.  
  76. signed main() {
  77. seriy();
  78. int n;
  79. cin >> n;
  80. if(pal(n)) {
  81. return cout << n << "\n" << 0, 0;
  82. }
  83. int cnt = 0;
  84. while(1) {
  85. cnt++;
  86. string s = "";
  87. int a1 = n;
  88. while(n > 0) {
  89. s += (char)((n % 10) + '0');
  90. n /= 10;
  91. }
  92. stringstream ss(s);
  93. int a2;
  94. ss >> a2;
  95. n = a1 + a2;
  96. if(pal(n)) {
  97. return cout << n << '\n' << cnt, 0;
  98. }
  99. }
  100. return 0;
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement