[Audio] check whether given number prime or not By T . Jaswanth Kumar Reddy.
[Audio] what is a prime number exactly ? a prime number is a number which has two divisors ( 1 and itself) and divisors must be unique 0 : 1 : 2 : 6 : : : it is not prime as division is not possible by 0 it is not prime as there is only 1 unique divisor 1 1 2 Count = 0.
[Audio] Count = 1. what is a prime number exactly ?.
[Audio] Count = 2. what is a prime number exactly ?.
[Audio] Count = 2 We have exactly two unique divisors so it is a prime number.
[Audio] 1 2 3 4 5 6. what is a prime number exactly ?.
[Audio] Count = 0. what is a prime number exactly ?.
[Audio] Count = 1. what is a prime number exactly ?.
[Audio] 1 2 3 4 5 6 Count = 2. what is a prime number exactly ?.
[Audio] Count = 3. what is a prime number exactly ?.
[Audio] . what is a prime number exactly ?. a prime number is a number which has two divisors ( 1 and itself) and divisors must be unique.
[Audio] . what is a prime number exactly ?. a prime number is a number which has two divisors ( 1 and itself) and divisors must be unique.
[Audio] 1 2 3 4 5 6 Count = 4. what is a prime number exactly ?.
[Audio] We have more than two divisors so it is not a prime number.
[Audio] 1 2 3 4 5 6 7 Count = 0. what is a prime number exactly ?.
[Audio] Count = 1. what is a prime number exactly ?.
[Audio] . what is a prime number exactly ?. a prime number is a number which has two divisors ( 1 and itself) and divisors must be unique.
[Audio] . what is a prime number exactly ?. a prime number is a number which has two divisors ( 1 and itself) and divisors must be unique.
[Audio] . what is a prime number exactly ?. a prime number is a number which has two divisors ( 1 and itself) and divisors must be unique.
[Audio] . what is a prime number exactly ?. a prime number is a number which has two divisors ( 1 and itself) and divisors must be unique.
[Audio] . what is a prime number exactly ?. a prime number is a number which has two divisors ( 1 and itself) and divisors must be unique.
[Audio] 1 2 3 4 5 6 7 Count = 2. what is a prime number exactly ?.
[Audio] We have exactly two divisors so it is a prime number 1 2 3 4 5 6 7.
[Audio] 1 2 3 4 5 6 7 8 9 Count = 0. what is a prime number exactly ?.
[Audio] 1 2 3 4 5 6 7 8 9 Count = 1. what is a prime number exactly ?.
[Audio] 1 2 3 4 5 6 7 8 9. what is a prime number exactly ?.
[Audio] Count = 2. what is a prime number exactly ?.
[Audio] . what is a prime number exactly ?. a prime number is a number which has two divisors ( 1 and itself) and divisors must be unique.
[Audio] . what is a prime number exactly ?. a prime number is a number which has two divisors ( 1 and itself) and divisors must be unique.
[Audio] . what is a prime number exactly ?. a prime number is a number which has two divisors ( 1 and itself) and divisors must be unique.
[Audio] . what is a prime number exactly ?. a prime number is a number which has two divisors ( 1 and itself) and divisors must be unique.
[Audio] . what is a prime number exactly ?. a prime number is a number which has two divisors ( 1 and itself) and divisors must be unique.
[Audio] 1 2 3 4 5 6 7 8 9 Count = 3. what is a prime number exactly ?.
[Audio] 1 2 3 4 5 6 7 8 9 We have more than two divisors so it is not a prime number.
[Audio] Input : N (any number) Output: True (if prime number) False (if not a prime number).
[Audio] Pseudo code :. Input : N (any number) Output: True (if prime number) False (if not a prime number).
[Audio] Pseudo code : function isPrime(n): ------------the input is given as parameter (Number).
[Audio] Pseudo code : function isPrime(n): ------------the input is given as parameter (Number) if n <= 1: ------------return false if given number is less than or equal to 1 return false.
[Audio] Pseudo code : function isPrime(n): ------------the input is given as parameter (Number) if n <= 1: ------------return false if given number is less than or equal to 1 return false int count = 0 ; ------------a variable to count number of divisors.
[Audio] Pseudo code : function isPrime(n): ------------the input is given as parameter (Number) if n <= 1: ------------return false if given number is less than or equal to 1 return false int count = 0 ; ------------a variable to count number of divisors for i from 1 to n: ------------changing a variable i from 1 to n if n % i == 0: -----------if i is divisor of n count++ -----------increment the count.
[Audio] Pseudo code : function isPrime(n): ------------the input is given as parameter (Number) if n <= 1: ------------return false if given number is less than or equal to 1 return false int count = 0 ; ------------a variable to count number of divisors for i from 1 to n: ------------changing a variable i from 1 to n if n % i == 0: -----------if i is divisor of n count++ -----------increment the count if count == 2: ---------if count is equal to 2 return true ---------it is a prime number else --------- else return false -------- it is not a prime number.
[Audio] Do we have to check all the numbers from 1 to n to know whether the given number is prime or not?.
[Audio] Let's improve the logic we know 1 and itself will always divide the number if n is greater than 2 so we can skip them right.
[Audio] Example :- 2 : Count = 0 removing 1 and itself will lead to count zero and prime numbers have zero divisors other than 1 and itself.
[Audio] : 6 : 2 3 4 5 count = 2 so it is not a prime number as 6 has divisors other than 1 and itself.
[Audio] : : : 2 3 4 5 count = 2 so it is not a prime number as 6 has divisors other than 1 and itself 2 3 4 5 6 count = 0 so it is a prime number as no divisors other than 1 and itself.
[Audio] : : : 9 : 2 3 4 5 6 7 8 count = 1 so it is not a prime number as it has 1 divisor other than 1 and itself.
[Audio] Do we have to check all the numbers from 1 to n to know whether the given number is prime or not?.
[Audio] Do we have to check all the numbers from 1 to n to know whether the given number is prime or not? Ans : if you find even one divisor while iterating you don’t have to continue the process it is not a prime number Example :- 9 : 2 3 4 5 6 7 8.
[Audio] Do we have to check all the numbers from 1 to n to know whether the given number is prime or not? Ans : if you find even one divisor while iterating you don’t have to continue the process it is not a prime number If we find a divisor it is not a prime.