Skip to content

Instantly share code, notes, and snippets.

@s4553711
Created February 24, 2018 15:06
Show Gist options
  • Save s4553711/c3618e943b72881a9e8670edd51369f8 to your computer and use it in GitHub Desktop.
Save s4553711/c3618e943b72881a9e8670edd51369f8 to your computer and use it in GitHub Desktop.
class Solution {
public:
int largestPalindrome(int n) {
int l = pow(10, n-1), r = pow(10, n) - 1;
for(int i = r; i>= 1; i--) {
string s = to_string(i);
string t = s;
reverse(t.begin(), t.end());
long ans = stol(s + t);
for(long j = r; j * j >= ans; j--)
if (ans % j == 0 && ans / j <= r) return ans % 1337;
}
return 9;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment