---
# System prepended metadata

title: S1C 利克瑞爾數
tags: [solution]

---

---
title: S1C 利克瑞爾數
tags: solution
---

# C. 利克瑞爾數
```cpp=
# include <iostream>
# include <algorithm>
using namespace std;

bool palindromic(string s){
    int l = s.size(), hf = l>>1;

    for(int x = 0 ; x<hf ; x++)
        if(s[x] != s[l-x-1])
            return false;

    return true;
}

int main(){
    unsigned long long n,k;
    string s;
    int add;
    bool ans;

    while(cin>>n && n){
        cout<<"Original number: "<<n<<'\n';
        k = n;
        add = 0;
        s = "0";

        while(!(ans = palindromic(s = to_string((n += stoull(s))))) && s.size() < 18){
            ++add;
            reverse(s.begin(), s.end());
        }

        if(ans)
            cout<<"Number of additions: "<<add<<"\nResult: "<<n<<"\n\n";
        else
            cout<<k<<" is Lychrel number\n\n";
    }
}
```