/
CODE
63 lines (52 loc) · 1.45 KB
/
CODE
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
#include <iostream>
#include "BigIntegerLibrary.hh"
using namespace std;
int main(){
int low, up;
cout << "Give me the lower bound of the sequence: " << endl;
cin >> low;
cout << "Give me the upper bound of the sequence: " << endl;
cin >> up;
BigInteger low1;
BigInteger up1;
up1 = up;
int countpal = 0;
int countnopal = 0;
int countly = 0;
int saved_low = low;
while(low <= up){
low1 = low;
string stringlow = bigIntegerToString(low1);
string stringwol;
copy(stringlow.rbegin(), stringlow.rend(),back_inserter(stringwol));
if(stringlow == stringwol){
countpal++;
low++;
} else {
int counter = 0;
BigInteger NewSum = low1;
BigInteger MusWen = stringToBigInteger(stringwol);
while (NewSum != MusWen && counter < 31){
NewSum = NewSum + MusWen;
string NewSumString = bigIntegerToString(NewSum);
string MusWenString;
copy(NewSumString.rbegin(), NewSumString.rend(),back_inserter(MusWenString));
MusWen = stringToBigInteger(MusWenString);
counter++;
}
if (counter >=31){
countly++;
cout << "Found Lycheral number: "<< low << endl;
low++;
}else{
countnopal++;
low++;
}
}
}
cout << "And the result are for range " << saved_low << " to " << up << endl;
cout << "Natural Palindromes: " << countpal << endl;
cout << "Natural Non Lychrels (become palindrome): " << countnopal << endl;
cout << "Lycheral candidates: " << countly << endl;
return 0;
}