Algorithms | Sololearn: Learn to code for FREE!



Can someone guide me about algorithm basics.. finding prime numbers, LCM, HCF

1/27/2018 3:12:08 PM

Grey Coder

3 Answers

New Answer


u can make your own algorithms ... just see what u need to find & what methods u know ... make use of them calculating hcf will be easy ... just find common factors in both & for lcm=product of no.'s /hcf of no.'s


@Grey Coder: I think, your question is a very good one, and may I extend your question a little bit: Are there any good books ore websites, which do an introduction for non computer science people? Which information sources could you recommend?


To test whether a number is prime try every number from 2 to sqrt(n). If any of them divides n, n is not prime. Greatest common divisor can be found by Euclidean algorithm. gcd(a,b) is the same as gcd(a-b,b), when a>b. if a==b, you have found it LCM is a*b/gcd(a,b). Further you can look up binary search or some graph algorithms, like DFS.