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.
importjava.io.*;importjava.util.*;importjava.text.*;importjava.math.*;importjava.util.regex.*;publicclassSolution{publicstaticvoidmain(String[]args){Scannerin=newScanner(System.in);longn=in.nextLong();longdigits=SUM1(n);longfactors=SUM2(n);if(digits==factors)System.out.print("1");elseSystem.out.print("0");/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */}publicstaticlongSUM1(longn){longs=0;while(n!=0){longrem=n%10;s=s+rem;longnum=n/10;n=num;}returns;}publicstaticlongSUM2(longn){longadd=0;while(n%2==0){add=add+2;n=n/2;}for(longj=3;j<=Math.sqrt(n);j=j+2){while(n%j==0){if(j>=10){longp=j;while(p!=0){longr=p%10;add=add+r;p=p/10;}}else{add=add+j;}n=n/j;}}if(n>1){while(n!=0){longr=n%10;add=add+r;n=n/10;}}returnadd;}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Identify Smith Numbers
You are viewing a single comment's thread. Return to all comments →
my code with all test cases submitted