Report Lychrel in New Logic/Math Puzzles Posted July 10, 2017 import java.util.*; public class lychrel { public static long palin(long n) { long m,p=0; while(n>0) { m=n%10; p=(p*10)+m; n=n/10; } return p; } public static void main(String ar[]) { long a,l,i,j=0,t,it=0; Scanner v=new Scanner(System.in); a=v.nextInt(); l=a+palin(a); t=palin(l); for(i=1;i<=10;i++) { it++; if(l==t) break; else { l=l+palin(l); t=palin(l); } if(i==4) j=l; } if(l!=t) { System.out.println(a+" is a Lychrel Number"); System.out.println("5th iteration of number "+a+" is "+j); } else System.out.println(it); } } 1
Lychrel
in New Logic/Math Puzzles
Posted
import java.util.*;
public class lychrel
{
public static long palin(long n)
{
long m,p=0;
while(n>0)
{
m=n%10;
p=(p*10)+m;
n=n/10;
}
return p;
}
public static void main(String ar[])
{
long a,l,i,j=0,t,it=0;
Scanner v=new Scanner(System.in);
a=v.nextInt();
l=a+palin(a);
t=palin(l);
for(i=1;i<=10;i++)
{
it++;
if(l==t)
break;
else
{
l=l+palin(l);
t=palin(l);
}
if(i==4)
j=l;
}
if(l!=t)
{
System.out.println(a+" is a Lychrel Number");
System.out.println("5th iteration of number "+a+" is "+j);
}
else
System.out.println(it);
}
}