Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class PalindromicPolite{
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int input = sc.nextInt();
- System.out.println(counter(input));
- }
- public static boolean isPalindromic(int x){
- String s = x + "";
- for (int i = 0; i<s.length(); i++) {
- if(s.charAt(i) != s.charAt(s.length()-i-1)){
- return false;
- }
- }
- return true;
- }
- public static boolean isPolite(int x){
- for (int i = 1; i < x/2+1; i++) {
- int guess = i;
- int nextNumber = i+1;
- while (guess < x) {
- guess += nextNumber;
- if (guess == x) {
- return true;
- }
- nextNumber++;
- }
- }
- return false;
- }
- public static int counter(int x){
- int count = 0;
- outerloop:
- for (int i = 0; true; i++) {
- count++;
- if (isPolite(i) == true && isPalindromic(i) == true && count == x) {
- break outerloop;
- }
- }
- return count;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement