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.
publicstaticintsolve(intnn){// Write your code hereintds=0;inttemp=nn;intn=nn;List<Integer>a=newArrayList<>();while(temp>0){ds+=temp%10;temp/=10;}while(n%2==0){a.add(2);n/=2;}for(inti=3;i<=Math.sqrt(n);i+=2){while(n%i==0){a.add(i);n/=i;}}if(n>2)a.add(n);intfsum=0;for(inti:a){while(i>0){fsum+=i%10;i=i/10;}}//System.out.println(a);if(fsum==ds)return1;return0;}
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 →