coder0687

Rishabh Gupta

Apr 13th, 2021 (edited)
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3. import static java.lang.System.*;
  4. class myCode
  5. {
  6.     /*
  7.     * @uthor for this solution : Rishabh Gupta
  8.     */
  9.     public static void main(String []args)throws IOException
  10.     {
  11.         BufferedReader br=new BufferedReader(new InputStreamReader(in));
  12.         PrintWriter out = new PrintWriter(System.out);
  13.         long n=Long.valueOf(br.readLine());
  14.         n+=reverse(n);
  15.         while(!isP(String.valueOf(n))) {
  16.             n+=reverse(n);
  17.         }
  18.         out.println(n);
  19.         out.flush();
  20.         out.close();
  21.     }
  22.     static long reverse(long n) {
  23.         long res=0;
  24.         while(n>0) {
  25.             res=res*10+n%10;
  26.             n/=10;
  27.         }
  28.         return res;
  29.     }
  30.     static boolean isP(String s) {
  31.         int l=0,r=s.length()-1;
  32.         while(l<r) {
  33.             if(s.charAt(l++)!=s.charAt(r--)) return false;
  34.         }
  35.         return true;
  36.     }
  37. }
Add Comment
Please, Sign In to add comment