1
00:00:01,720 --> 00:00:03,370
Hey, guys, what's up?

2
00:00:03,880 --> 00:00:10,660
So today we are solving an interesting problem, so the problem statement is so given a number and given

3
00:00:10,660 --> 00:00:14,710
a number and we have to check whether this number is prime or not.

4
00:00:15,670 --> 00:00:17,500
So how do check with their numbers prime?

5
00:00:17,800 --> 00:00:19,570
So first of all, what do you mean by prime?

6
00:00:19,910 --> 00:00:22,720
So prime number is a number that has only two factors.

7
00:00:23,080 --> 00:00:24,690
One and itself.

8
00:00:26,120 --> 00:00:28,850
For example, Dhoom is a prime number, it has two factors.

9
00:00:28,880 --> 00:00:31,060
One, two, five is the prime number.

10
00:00:31,190 --> 00:00:32,090
It has two factors.

11
00:00:32,120 --> 00:00:32,990
One in five.

12
00:00:33,510 --> 00:00:34,570
Thirteen is a prime number.

13
00:00:34,580 --> 00:00:35,480
It has two factors.

14
00:00:35,510 --> 00:00:40,550
One and had been similarly, 17 is a prime number because it has two factors.

15
00:00:40,970 --> 00:00:44,750
Fifteen is not a prime number because it has more than two factors.

16
00:00:46,080 --> 00:00:46,360
OK.

17
00:00:46,660 --> 00:00:50,160
So this is not prime, this all four the frames.

18
00:00:50,710 --> 00:00:53,110
So the question is, will be given a number.

19
00:00:53,440 --> 00:00:58,220
And I have to report to the user whether that number is prime or Ligue in numbers, not prime.

20
00:00:58,690 --> 00:01:01,210
So how we can check with our number is Paymer not.

21
00:01:01,510 --> 00:01:04,360
So what I will do, I will start dividing that number by two.

22
00:01:04,930 --> 00:01:05,750
I will divide by two.

23
00:01:05,770 --> 00:01:06,720
Then I will divide by three.

24
00:01:06,790 --> 00:01:07,840
Then I will divide by four.

25
00:01:08,170 --> 00:01:11,230
And I will keep dividing on Bill and minus one.

26
00:01:12,310 --> 00:01:18,940
If out of these number, if out of all these numbers, if I get just anyone number, if I get any one

27
00:01:18,940 --> 00:01:28,030
number that divides and then I can see that the number N is not prime number.

28
00:01:28,570 --> 00:01:30,430
This is not prime either.

29
00:01:30,430 --> 00:01:33,400
Revise the number and is a prime number.

30
00:01:33,940 --> 00:01:36,610
OK, so what I need here is I will use a loop.

31
00:01:36,910 --> 00:01:43,450
So this loop will start from this loop will start from two and this loop will go till and minus one.

32
00:01:43,750 --> 00:01:44,890
And I will do eight plus.

33
00:01:44,890 --> 00:01:45,910
Plus what I will do.

34
00:01:45,940 --> 00:01:49,900
I will check if the number N is usable by I.

35
00:01:50,370 --> 00:01:53,470
I can say this number is not prime.

36
00:01:56,290 --> 00:01:57,010
A lot of eyes.

37
00:01:57,160 --> 00:01:58,570
This number is prime.

38
00:01:59,040 --> 00:02:01,600
So so let's write the code for it.

39
00:02:04,650 --> 00:02:05,730
So let's name it.

40
00:02:07,790 --> 00:02:08,010
Check.

41
00:02:08,320 --> 00:02:08,760
Fame.

42
00:02:11,010 --> 00:02:11,880
Nard CVB.

43
00:02:22,400 --> 00:02:26,410
So what I will do, I will take a No N and fundi user.

44
00:02:27,650 --> 00:02:32,390
Now our logic was we will try to divide this number in starting from two.

45
00:02:32,450 --> 00:02:33,470
So I equals two.

46
00:02:34,730 --> 00:02:39,950
While I is less than or equal to N minus one.

47
00:02:40,940 --> 00:02:41,990
Now what we have to do.

48
00:02:42,470 --> 00:02:43,240
I will check.

49
00:02:44,420 --> 00:02:49,870
I will check if the given number N is there as well by I.

50
00:02:50,720 --> 00:02:53,750
That means this number is not a frame.

51
00:02:53,810 --> 00:02:54,650
So C out.

52
00:02:56,040 --> 00:02:56,730
C out.

53
00:02:56,870 --> 00:03:00,850
This number is not prime.

54
00:03:02,200 --> 00:03:02,540
OK.

55
00:03:03,020 --> 00:03:04,850
And our work is complete.

56
00:03:04,910 --> 00:03:06,770
So I will break this loop.

57
00:03:08,370 --> 00:03:10,770
He and I will be having a plus plus.

58
00:03:13,820 --> 00:03:21,050
And if this loop this way loop got terminated naturally.

59
00:03:21,850 --> 00:03:25,160
Let me use my big statement has never been executed.

60
00:03:25,670 --> 00:03:30,590
Then I can say this number is definitely a prime number.

61
00:03:32,360 --> 00:03:32,650
OK.

62
00:03:32,990 --> 00:03:34,520
So this is all that we have to do.

63
00:03:35,540 --> 00:03:36,280
Now, let's see.

64
00:03:39,220 --> 00:03:41,230
So let's take an example.

65
00:03:41,980 --> 00:03:44,450
So let's take the example N equals four.

66
00:03:44,760 --> 00:03:44,980
OK.

67
00:03:45,060 --> 00:03:50,410
So any equals for now, I will try to divide that number by to divide the number by two.

68
00:03:50,770 --> 00:03:53,560
So for Marda, two equals zero.

69
00:03:53,800 --> 00:03:54,190
Yes.

70
00:03:54,790 --> 00:03:55,710
The condition is true.

71
00:03:56,170 --> 00:03:57,390
See out not prime.

72
00:03:57,760 --> 00:04:02,140
So I reprint Nart prime and break.

73
00:04:02,740 --> 00:04:05,010
Break means come out of the loop.

74
00:04:05,320 --> 00:04:07,870
So I will reach at line number 19.

75
00:04:08,200 --> 00:04:11,030
I will check if I is ever live either way.

76
00:04:11,100 --> 00:04:11,740
If I is to.

77
00:04:12,040 --> 00:04:13,960
So if I equals equals four.

78
00:04:14,110 --> 00:04:15,280
No this is not true.

79
00:04:15,730 --> 00:04:17,050
So I will reach here.

80
00:04:17,140 --> 00:04:18,010
Return zero.

81
00:04:18,210 --> 00:04:19,010
So I'm out for days.

82
00:04:19,150 --> 00:04:19,990
Not fine.

83
00:04:20,830 --> 00:04:21,100
OK.

84
00:04:21,520 --> 00:04:23,790
Now let us take the case of a prime number.

85
00:04:25,490 --> 00:04:26,370
So what will happen?

86
00:04:27,390 --> 00:04:29,830
So let's see, And equals five.

87
00:04:29,940 --> 00:04:31,110
So five is a prime number.

88
00:04:31,140 --> 00:04:32,010
So what will happen?

89
00:04:33,160 --> 00:04:34,840
I will try to do at the number by two.

90
00:04:35,050 --> 00:04:38,230
So five more do it equals zero.

91
00:04:38,320 --> 00:04:39,510
No other condition is false.

92
00:04:40,000 --> 00:04:43,830
Then I will try to do that number by three condition is false.

93
00:04:44,380 --> 00:04:47,410
Then I will try to reduce the number by for the condition is false.

94
00:04:47,740 --> 00:04:48,480
Now what will happen.

95
00:04:48,490 --> 00:04:50,170
The value of five will become five.

96
00:04:52,320 --> 00:04:56,240
As the video fight becomes, it goes to end this loop this way loop.

97
00:04:56,580 --> 00:04:58,800
Well, it got terminated naturally.

98
00:04:59,670 --> 00:05:03,030
Okay, so a big statement has never been executed.

99
00:05:03,360 --> 00:05:06,410
So I will reach here is five.

100
00:05:06,540 --> 00:05:07,740
Equals equals five.

101
00:05:07,800 --> 00:05:09,360
Yet the condition is to print.

102
00:05:10,070 --> 00:05:13,620
So for any equals five miles for this brain which is hundred percent.

103
00:05:13,650 --> 00:05:14,130
Correct.

104
00:05:14,880 --> 00:05:15,170
OK.

105
00:05:15,930 --> 00:05:18,240
So this big is very important.

106
00:05:18,300 --> 00:05:21,070
If you will not try to break your heart would really be wrong.

107
00:05:22,990 --> 00:05:29,880
OK, so one more time, if there is no eye that divides, and I will point out not prime.

108
00:05:30,150 --> 00:05:32,130
And I will break the loop.

109
00:05:32,610 --> 00:05:32,840
OK.

110
00:05:33,180 --> 00:05:34,380
So I will break the loop.

111
00:05:34,410 --> 00:05:36,630
I will likely reach line number 19.

112
00:05:37,110 --> 00:05:41,250
And this condition will definitely be false if Blake's treatment is executed.

113
00:05:41,610 --> 00:05:43,140
This condition will be false.

114
00:05:43,590 --> 00:05:47,550
And if the number is prime, then this condition will be false.

115
00:05:47,980 --> 00:05:50,840
And I will become equals to end the violence.

116
00:05:50,910 --> 00:05:53,810
We've got a murder naturally and I will end.

117
00:05:53,850 --> 00:05:55,290
This condition would become true.

118
00:05:55,420 --> 00:05:56,580
Then the number is prime.

119
00:05:57,120 --> 00:05:59,520
Let's see whether our goal is working, correct or not.

120
00:05:59,850 --> 00:06:00,640
For example.

121
00:06:00,750 --> 00:06:01,170
Five.

122
00:06:01,260 --> 00:06:02,750
So five is a prime number.

123
00:06:05,850 --> 00:06:08,780
So Tartine is also a prime number.

124
00:06:10,930 --> 00:06:13,870
So Ford is not prime.

125
00:06:16,400 --> 00:06:19,430
Similarly, Ben is not prime.

126
00:06:21,050 --> 00:06:26,720
OK, so this is the code for checking whether the given number is a prime number or not.

127
00:06:27,170 --> 00:06:29,330
So if you have any doubt, feel free to ask.

128
00:06:29,720 --> 00:06:29,980
OK.

129
00:06:30,110 --> 00:06:31,400
So this is it for this video.

130
00:06:31,580 --> 00:06:32,150
Thank you.
