মিস্টেরি নাম্বার — যেসব সংখ্যা দুটি সংখ্যার যোগফল হিসেবে লেখা যায়, যেখানে দুটি সংখ্যাটি একে অপরের রিভার্স।
উদাহরণ
121 = 29 + 92 (29 ও 92 একে অপরের রিভার্স)
C++ কোড উদাহরণ
#include <bits/stdc++.h>
using namespace std;
int reverseNum(int n) {
string s = to_string(n);
reverse(s.begin(), s.end());
return stoi(s);
}
bool isMystery(int n) {
for (int i=1; i<=n/2; i++) {
int j = reverseNum(i);
if (i + j == n) {
cout << i << " " << j << " ";
return true;
}
}
return false;
}
int main() {
int n = 121;
if (isMystery(n)) cout << n << " is a Mystery number";
else cout << n << " is not a Mystery number";
return 0;
}
আউটপুট
29 92 121 is a Mystery number