Hey, guys, what's up?
So today we are solving an interesting problem, so the problem statement is so given a number and given
a number and we have to check whether this number is prime or not.
So how do check with their numbers prime?
So first of all, what do you mean by prime?
So prime number is a number that has only two factors.
One and itself.
For example, Dhoom is a prime number, it has two factors.
One, two, five is the prime number.
It has two factors.
One in five.
Thirteen is a prime number.
It has two factors.
One and had been similarly, 17 is a prime number because it has two factors.
Fifteen is not a prime number because it has more than two factors.
OK.
So this is not prime, this all four the frames.
So the question is, will be given a number.
And I have to report to the user whether that number is prime or Ligue in numbers, not prime.
So how we can check with our number is Paymer not.
So what I will do, I will start dividing that number by two.
I will divide by two.
Then I will divide by three.
Then I will divide by four.
And I will keep dividing on Bill and minus one.
If out of these number, if out of all these numbers, if I get just anyone number, if I get any one
number that divides and then I can see that the number N is not prime number.
This is not prime either.
Revise the number and is a prime number.
OK, so what I need here is I will use a loop.
So this loop will start from this loop will start from two and this loop will go till and minus one.
And I will do eight plus.
Plus what I will do.
I will check if the number N is usable by I.
I can say this number is not prime.
A lot of eyes.
This number is prime.
So so let's write the code for it.
So let's name it.
Check.
Fame.
Nard CVB.
So what I will do, I will take a No N and fundi user.
Now our logic was we will try to divide this number in starting from two.
So I equals two.
While I is less than or equal to N minus one.
Now what we have to do.
I will check.
I will check if the given number N is there as well by I.
That means this number is not a frame.
So C out.
C out.
This number is not prime.
OK.
And our work is complete.
So I will break this loop.
He and I will be having a plus plus.
And if this loop this way loop got terminated naturally.
Let me use my big statement has never been executed.
Then I can say this number is definitely a prime number.
OK.
So this is all that we have to do.
Now, let's see.
So let's take an example.
So let's take the example N equals four.
OK.
So any equals for now, I will try to divide that number by to divide the number by two.
So for Marda, two equals zero.
Yes.
The condition is true.
See out not prime.
So I reprint Nart prime and break.
Break means come out of the loop.
So I will reach at line number 19.
I will check if I is ever live either way.
If I is to.
So if I equals equals four.
No this is not true.
So I will reach here.
Return zero.
So I'm out for days.
Not fine.
OK.
Now let us take the case of a prime number.
So what will happen?
So let's see, And equals five.
So five is a prime number.
So what will happen?
I will try to do at the number by two.
So five more do it equals zero.
No other condition is false.
Then I will try to do that number by three condition is false.
Then I will try to reduce the number by for the condition is false.
Now what will happen.
The value of five will become five.
As the video fight becomes, it goes to end this loop this way loop.
Well, it got terminated naturally.
Okay, so a big statement has never been executed.
So I will reach here is five.
Equals equals five.
Yet the condition is to print.
So for any equals five miles for this brain which is hundred percent.
Correct.
OK.
So this big is very important.
If you will not try to break your heart would really be wrong.
OK, so one more time, if there is no eye that divides, and I will point out not prime.
And I will break the loop.
OK.
So I will break the loop.
I will likely reach line number 19.
And this condition will definitely be false if Blake's treatment is executed.
This condition will be false.
And if the number is prime, then this condition will be false.
And I will become equals to end the violence.
We've got a murder naturally and I will end.
This condition would become true.
Then the number is prime.
Let's see whether our goal is working, correct or not.
For example.
Five.
So five is a prime number.
So Tartine is also a prime number.
So Ford is not prime.
Similarly, Ben is not prime.
OK, so this is the code for checking whether the given number is a prime number or not.
So if you have any doubt, feel free to ask.
OK.
So this is it for this video.
Thank you.