Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- import static java.lang.System.*;
- class myCode
- {
- /*
- * @uthor for this solution : Rishabh Gupta
- */
- public static void main(String []args)throws IOException
- {
- BufferedReader br=new BufferedReader(new InputStreamReader(in));
- PrintWriter out = new PrintWriter(System.out);
- long n=Long.valueOf(br.readLine());
- n+=reverse(n);
- while(!isP(String.valueOf(n))) {
- n+=reverse(n);
- }
- out.println(n);
- out.flush();
- out.close();
- }
- static long reverse(long n) {
- long res=0;
- while(n>0) {
- res=res*10+n%10;
- n/=10;
- }
- return res;
- }
- static boolean isP(String s) {
- int l=0,r=s.length()-1;
- while(l<r) {
- if(s.charAt(l++)!=s.charAt(r--)) return false;
- }
- return true;
- }
- }
Add Comment
Please, Sign In to add comment