fork(1) download
  1. /*Author : Siriuslight | Subham Pal
  2.   Army Institute of Technology
  3. */
  4. #include<bits/stdc++.h>
  5. #define FIO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
  6. #define sd(x) scanf("%d", &x);
  7. #define sld(x) scanf("%lld", &x);
  8. using namespace std; typedef long long ll; typedef long double ld;
  9. const ll inf = 1e9, N = 1e5+5;
  10. const ll INF = 1e18, MOD = 1e9+7;
  11. ll powmod(ll a,ll b,ll m=MOD){ll r=1;while(b>0){if(b&1)r=r*a%m;a=a*a%m;b>>=1;}return r;}
  12. ll power(ll a,ll b){ll r=1;while(b>0){if(b&1)r=r*a;a=a*a;b>>=1;}return r;}
  13. ll gcd(ll a,ll b){if(b>a)swap(a,b);if(!b)return a;return gcd(b,a%b);}
  14.  
  15. int ans(0);
  16.  
  17. bool palin(vector<int> v){
  18. for(int i = 0; i < v.size() / 2; ++i)
  19. if(v[i] != v[v.size() - 1 - i])
  20. return 0;
  21. return 1;
  22. }
  23.  
  24. vector <int> add(vector <int> v1){
  25. vector <int> v2, res;
  26. v2 = v1;
  27. reverse(v2.begin(), v2.end());
  28. int carry(0);
  29. for(int i = v1.size() - 1; i >= 0; --i){
  30. int t = v1[i] + v2[i] + carry;
  31. res.push_back(t % 10);
  32. carry = t / 10;
  33. }
  34. while(carry){
  35. res.push_back(carry % 10);
  36. carry /= 10;
  37. }
  38. reverse(res.begin(), res.end());
  39. return res;
  40. }
  41.  
  42. bool lychrel(int x){
  43. vector <int> v;
  44. while(x){
  45. v.push_back(x % 10);
  46. x /= 10;
  47. }
  48. reverse(v.begin(), v.end());
  49. for(int i = 0; i <= 50; ++i){
  50. if(palin(v)){
  51. return 0;
  52. }
  53. v = add(v);
  54. }
  55. return 1;
  56. }
  57.  
  58. int main(){
  59. FIO;
  60. cout << setprecision(10) << fixed;
  61.  
  62. for(int i = 1; i < 1e4; ++i){
  63. ans += lychrel(i);
  64. }
  65. cout << ans;
  66. return 0;
  67. }
Success #stdin #stdout 0.03s 4356KB
stdin
Standard input is empty
stdout
246