You are viewing a single comment's thread. Return to all comments →
void kaprekarNumbers(int p, int q) { bool found = false; for (int i = p; i <= q; i++) { long long sq = 1LL * i * i; string num_str = to_string(sq); int len = num_str.length(); int mid = len / 2; long long left = (mid == 0) ? 0 : stoll(num_str.substr(0, mid)); long long right = stoll(num_str.substr(mid)); if (left + right == i) { found = true; cout << i << " "; } } if (!found) cout << "INVALID RANGE"; }
Seems like cookies are disabled on this browser, please enable them to open this website
Modified Kaprekar Numbers
You are viewing a single comment's thread. Return to all comments →