- #1
hadi amiri 4
- 98
- 1
Homework Statement
1- write an algorithm to find out whether an input is a prime number
or not.
2-write aa program to compute square root by Newton method
3-write an algorithm to show an input is perfect or not.
4-
Before getting any help on this forum, you need to show what you have tried to do.hadi amiri 4 said:Homework Statement
1- write an algorithm to find out whether an input is a prime number
or not.
2-write aa program to compute square root by Newton method
3-write an algorithm to show an input is perfect or not.
4-
Homework Equations
The Attempt at a Solution
The algorithm checks if the input number is divisible by any number other than 1 and itself. If it is not divisible by any other number, then it is considered a prime number.
The time complexity of this algorithm is O(sqrt(n)), where n is the input number. This means that the algorithm's runtime increases proportionally to the square root of the input number.
Yes, this algorithm can be used for large numbers. However, as the input number increases, the runtime of the algorithm also increases, making it less efficient for very large numbers.
One limitation of this algorithm is that it can only determine if a number is prime or not. It does not provide any information on the factors of the number.
Yes, there are many other algorithms for finding prime numbers, such as the Sieve of Eratosthenes and the Miller-Rabin primality test. Each algorithm has its own advantages and disadvantages, and the best one to use depends on the specific situation.