```
public int largestPalindrome(int n) {
if (n == 1) return 9;
for (long max = (long) Math.pow(10, n) - 1, min = max / 10, half = max * max / (long) Math.pow(10, n);; half--)
for (long i = max, palindrom = Long.parseLong(half + new StringBuilder(half + "").reverse().toString()); i > min && i * max >= palindrom && palindrom > min * i; i--)
if (palindrom % i == 0) return (int) (palindrom % 1337);
}
```