We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Actually it was a pretty simple problem here the solution given by him is also bit complex a simpler solution is that just loop untill your number is not equal to 1. check this code out
int m=n;
int sum1=0;
int sum2=0;
while(m!=0)
{
sum1+=m%10;
m=m/10;
}
m=n;
while(m!=1)
{
for(int i=2;i<=m;i++)
{
if(m%i==0)
{
System.out.println(i);
m=m/i;
int k=i;
while(k!=0)
{
sum2+=(k%10);
k=k/10;
}
break;
}
}
}
System.out.println(sum1);
System.out.println(sum2);
if(sum1==sum2)
return 1;
else
return 0;
Identify Smith Numbers
You are viewing a single comment's thread. Return to all comments →
Actually it was a pretty simple problem here the solution given by him is also bit complex a simpler solution is that just loop untill your number is not equal to 1. check this code out int m=n; int sum1=0; int sum2=0; while(m!=0) { sum1+=m%10; m=m/10; } m=n; while(m!=1) { for(int i=2;i<=m;i++) { if(m%i==0) { System.out.println(i); m=m/i; int k=i; while(k!=0) { sum2+=(k%10); k=k/10; } break; } } } System.out.println(sum1); System.out.println(sum2); if(sum1==sum2) return 1; else return 0;