# Identify Smith Numbers

# Identify Smith Numbers

edzvh + 2 comments Having spent 20 mins googling prime factorization algorithms I fail to see how this is an "easy" problem. Maybe I'm just being a thicko.

nebasuke + 1 comment Indeed, making this a 10 point easy warmup problem is really undervaluing the hardness of solving this, especially comparing to all of the other easy 20 point solutions.

Shafaet + 1 comment Well its not a hard or medium problem :). May be it should have 20 points, but not more than that.

chawlanmol + 0 comments [deleted]

bennattj + 1 comment Well a pretty simple/naive prime factorization algorithm works for the test cases. All you need to do is find the first factor (start testing with 2). The first number you find that works is guaranteed to be a prime number. Then keep dividing until the number is no longer divisible by that prime--keep the count (since you'll need that later). Then keep going until the number becomes 1.

Now I don't know whether or not you need the following "optimization", but I used it because I already had it from the Primitive Number problem. If the last number you end up with is a large prime, then you might needlessly test a bunch of numbers only to find out that there weren't any (i.e. it was prime). Use the fact that if two factors exist they will be on either side of the square root. So if the number you are currently testing, squares to something larger than the remaining number, then that number must be prime and you can quit and just add one instance of that large prime (rather than testing all of the numbers greater than the square root of that large prime--which will require substantially more testing than up to the square root).

pgmreddy + 0 comments About 10% is unclear on what you said. I din't do Primitive Number due to it's success rate (may be you are reffering to https://www.hackerrank.com/challenges/primitive-problem)

I did completely different way. Passed on 1st submission for all tests,but it took 2 hour to make it run, also because of out of memory problem. I did some other optimizations.

Definitely either not easy, or not 20 points. Following is 50, but took 1/2 the time. https://www.hackerrank.com/challenges/john-and-gcd-list/problem

Somehow points are not right for problems.

algaey + 1 comment Please check your test case answers 4937775 for example shows it is a Smith number but one of its prime factors is 65837!! how can this be a smith no. I'm pretty sure my program is correct so please check the answers to the test cases

YoungBlood + 1 comment "A Smith number is a composite number, the sum of whose digits is

`THE SUM OF THE DIGITS`

of its prime factors obtained as a result of prime factorization (excluding 1)." So when you add up the prime factors of 4937775 (which are 3, 5, 5 and 65837) you will add them like this:`3+5+5+6+5+8+3+7`

(which is equal to`4+9+3+7+7+7+5`

)algaey + 0 comments tnx a lot bro...got it working now

abhishek93131 + 0 comments my code with all test cases submitted

import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static void main(String[] args) { Scanner in=new Scanner(System.in); long n=in.nextLong(); long digits=SUM1(n); long factors=SUM2(n); if(digits==factors) System.out.print("1"); else System.out.print("0"); /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ } public static long SUM1(long n) { long s=0; while(n!=0) { long rem=n%10; s=s+rem; long num=n/10; n=num; } return s; } public static long SUM2(long n) { long add=0; while(n%2==0) { add=add+2; n=n/2; } for(long j=3;j<=Math.sqrt(n);j=j+2) { while(n%j==0) { if(j>=10) { long p=j; while(p!=0) { long r=p%10; add=add+r; p=p/10; }} else { add=add+j; } n=n/j; } } if(n>1) { while(n!=0) { long r=n%10; add=add+r; n=n/10; } } return add; } }

gotRefill + 2 comments Wow. I got it, but this one being tagged as "easy" has to be a joke. :D

I'm real worried about the "hard" problems now, if this is "easy".

patheyshah + 1 comment 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;

pgmreddy + 0 comments May be pretty simple, you should try 100 rank in Math domain.

pgmreddy + 0 comments

arianapham + 0 comments You will understand what is important through bloxorz the idea of providing one of the links with an interesting website

starjackioaz + 0 comments The article is really nice and interesting. I have searched for this type of information and would love to read this information. I hope you will share more useful articles like that. Thanks for sharing! starjack io

marcel18 + 0 comments Thanks for sharing. This article is very clear explanation on topic. I admired for you're work. Hope to update more articles which are used for students as well as teachers.... Titan gel Reviews

millieallen121 + 0 comments I found an idea for smith number indentification on internet The idea was to first use Sienda from Sundaram to find all of the spaces below the border (this is especially useful if we want to control Smith's multiples). Now, for each input, we repeat Smith to check all its key elements and find the sum of the numbers of each key component. We also find the sum of these numbers. Finally, I just say that I am student I have to write my program using java so I saw MyAssignmentHelp Reviews and took assistance about smith number indentification and they also shared different ways. we compare the two quantities. If they are the same, we will return.

Here is the link: https://www.geeksforgeeks.org/smith-number/

Warnersun + 0 comments Hey thank you so much for sharing article. You clarify my doubts which are am facing now. And very clear explanation on topic. Thanks again for doing this great job. Even am waiting for more updates regarding this kind of articles.....

prasunmazumder + 0 comments What is the problem in my solution . Test case 2 and Test case 9 are not passing and its showing run time errors ? Thanks !!

import java.io.

*; import java.math.*; import java.text.*; import java.util.*; import java.util.regex.*;public class Solution { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int prime = getPrimeFactors(n); int sum = getSum(n); if ( prime == sum) System.out.print(1); else System.out.print(0); sc.close(); }

`static int getSum(int n){ int sum = 0 ; while ( n > 0){ sum += n%10; n = n/10; } return sum;`

}

`static int getPrimeFactors(int n){ int result = 0 ; while ( n%2 == 0){ result += 2 ; n = n/2; } for( int i=3 ; i <= Math.sqrt(n) ; i+=2){ while ( n % i == 0){ if ( i > 9){ while ( i > 0){ result += i%10; i=i/10; } } else{ result += i; n = n/i; } } } if ( n > 2){ if ( n > 9){ while ( n > 0){ result += n%10; n=n/10; } } else result +=n; } return result; }`

}

Sort 66 Discussions, By:

Please Login in order to post a comment