/
wsq11.cpp
78 lines (74 loc) · 1.45 KB
/
wsq11.cpp
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <string>
#include <iostream>
#include "BigIntegerLibrary.hh"
using namespace std;
bool is_palindrome(BigInteger n)
{
string s = bigIntegerToString (n);
reverse (s.begin(), s.end());
BigInteger bi = stringToBigInteger (s);
if (n == bi)
{
return true;
} else
{
return false;
}
}
BigInteger apply196(BigInteger n)
{
string s2 = bigIntegerToString (n);
reverse (s2.begin(), s2.end());
BigInteger bi = stringToBigInteger (s2);
n = n + bi;
return n;
}
int main() {
int lb;
int up;
int np = 0;
int nl = 0;
int l = 0;
BigInteger bn;
cout << "Write the lower bound: ";
cin >> lb;
cout << "Write the upper bound: ";
cin >> ub;
cout << endl;
for (int i=lb; i<=ub; i++)
{
if(is_palindrome(i)==true)
{
cout << "This number is a natural palindrome" << endl;
np++;
} else
{
bn = apply196 (i);
for(int j=1; j<=30; j++)
{
if(is_palindrome (bn)==true)
{
cout << "This is a non-Lychrel number"<<endl;
nl++;
break;
} else
{
bn = apply196 (bn);
}
}
if (is_palindrome(bn) == false){
cout<<"This is a Lychrel number"<<endl;
l++;
cout<<endl;
}
}
}
cout << endl;
cout << "Analysis Report: " << endl;
cout << endl;
cout << "Number of Values Analyzed: " << (ub-lb) + 1 << endl;
cout << "Number of Natural Palindromes: " << np << endl;
cout << "Number of Non-Lychrel Numbers: " << nl << endl;
cout << "Number of Lychrel Numbers: " << l << endl;
return 0;
}