check whether given number prime or not

Published on
Embed video
Share video
Ask about this video

Scene 1 (0s)

[Audio] check whether given number prime or not By T . Jaswanth Kumar Reddy.

Scene 2 (2s)

[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.

Scene 3 (20s)

[Audio] Count = 1. what is a prime number exactly ?.

Scene 4 (22s)

[Audio] Count = 2. what is a prime number exactly ?.

Scene 5 (24s)

[Audio] Count = 2 We have exactly two unique divisors so it is a prime number.

Scene 6 (27s)

[Audio] 1 2 3 4 5 6. what is a prime number exactly ?.

Scene 7 (29s)

[Audio] Count = 0. what is a prime number exactly ?.

Scene 8 (31s)

[Audio] Count = 1. what is a prime number exactly ?.

Scene 9 (33s)

[Audio] 1 2 3 4 5 6 Count = 2. what is a prime number exactly ?.

Scene 10 (36s)

[Audio] Count = 3. what is a prime number exactly ?.

Scene 11 (39s)

[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.

Scene 12 (41s)

[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.

Scene 13 (43s)

[Audio] 1 2 3 4 5 6 Count = 4. what is a prime number exactly ?.

Scene 14 (45s)

[Audio] We have more than two divisors so it is not a prime number.

Scene 15 (48s)

[Audio] 1 2 3 4 5 6 7 Count = 0. what is a prime number exactly ?.

Scene 16 (51s)

[Audio] Count = 1. what is a prime number exactly ?.

Scene 17 (53s)

[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.

Scene 18 (55s)

[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.

Scene 19 (57s)

[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.

Scene 20 (1m 0s)

[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.

Scene 21 (1m 2s)

[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.

Scene 22 (1m 4s)

[Audio] 1 2 3 4 5 6 7 Count = 2. what is a prime number exactly ?.

Scene 23 (1m 7s)

[Audio] We have exactly two divisors so it is a prime number 1 2 3 4 5 6 7.

Scene 24 (1m 10s)

[Audio] 1 2 3 4 5 6 7 8 9 Count = 0. what is a prime number exactly ?.

Scene 25 (1m 12s)

[Audio] 1 2 3 4 5 6 7 8 9 Count = 1. what is a prime number exactly ?.

Scene 26 (1m 15s)

[Audio] 1 2 3 4 5 6 7 8 9. what is a prime number exactly ?.

Scene 27 (1m 17s)

[Audio] Count = 2. what is a prime number exactly ?.

Scene 28 (1m 19s)

[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.

Scene 29 (1m 22s)

[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.

Scene 30 (1m 24s)

[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.

Scene 31 (1m 27s)

[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.

Scene 32 (1m 29s)

[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.

Scene 33 (1m 32s)

[Audio] 1 2 3 4 5 6 7 8 9 Count = 3. what is a prime number exactly ?.

Scene 34 (1m 34s)

[Audio] 1 2 3 4 5 6 7 8 9 We have more than two divisors so it is not a prime number.

Scene 35 (1m 37s)

[Audio] Input : N (any number) Output: True (if prime number) False (if not a prime number).

Scene 36 (1m 38s)

[Audio] Pseudo code :. Input : N (any number) Output: True (if prime number) False (if not a prime number).

Scene 37 (1m 41s)

[Audio] Pseudo code : function isPrime(n): ------------the input is given as parameter (Number).

Scene 38 (1m 43s)

[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.

Scene 39 (1m 45s)

[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.

Scene 40 (1m 47s)

[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.

Scene 41 (1m 52s)

[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.

Scene 42 (1m 56s)

[Audio] Do we have to check all the numbers from 1 to n to know whether the given number is prime or not?.

Scene 43 (1m 59s)

[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.

Scene 44 (2m 3s)

[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.

Scene 45 (2m 6s)

[Audio] : 6 : 2 3 4 5 count = 2 so it is not a prime number as 6 has divisors other than 1 and itself.

Scene 46 (2m 8s)

[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.

Scene 47 (2m 10s)

[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.

Scene 48 (2m 13s)

[Audio] Do we have to check all the numbers from 1 to n to know whether the given number is prime or not?.

Scene 49 (2m 16s)

[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.

Scene 50 (2m 20s)

[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.