Check if a number is prime (Algorithm/code/program)

preview_player
Показать описание
Check if a number is prime. Check prime number in C.
Рекомендации по теме
Комментарии
Автор

In Square Root method, the loop should start from "i=2". Everything else is just awesome

asim-gandu-phenchod
Автор

For sqrt method, the initial value of i in the loop shall start from 2 and not 0. And also to keep it simple, we can make the condition as i*i <=n.

parasbansal
Автор

Its helping me lot, being a beginner i cant understand before seeing ur video but now am happy .keep sharing ur knowledge sir, thank u so much🤗

amudharasik
Автор

In the case of 29, you ONLY have to divide by the prime factor 3 and see if it comes out even. The prime factors involved in trial division are all the prime numbers except 2 and 5 (any even number is divisible by 2 and therefore composite, and any number that ends in 5 or 0 is divisible by 5 and therefore composite). So the prime factors used are 3, 7, 11, 13, 17, 19, and so on. The square root of the number being tested must be larger than the prime factors you are dividing by. For example, the square of 7 is 49, which is larger than 29, so you don't have to divide 29 by 7 (or larger). Just the 3 will do. If you had the number 59, you'd have to divide by 3 AND 7. If you had 131, you'd have to divide by 3, 7, and 11 unless you find factors when dividing by either 3 or 7. Once you get two factors, you can find all the prime factors from those two and don't have to do any more trial division. Unless... you get a factor and have to use trial division to determine whether the factor is prime. It gets tough when the number is over about two thousand.

jeffw
Автор

Please make more videos on java your way of explanation is very excellent and I am very excited to learn

ravichandu
Автор

You can better use the 6n+/-1 form to solve that problem in constant time, instead of using iteration.

hernantenjo
Автор

Really i understood very well just because of u sir! Do more on this topic like alternative prime number and count of prime numbers between a range.its my humble request sir!

shalinibaskar
Автор

Thank you very much. The best tutorial so far.

HoanNguyen-fcvb
Автор

Gotta love ppl like him. Awesome explanation

serhoots
Автор

This is really a fundamental algo. Pls do more of graph theory and trees and dp. That helps a lot....

natesh
Автор

Amazing tutorial, sir! Thank you so much for the video, it's truly easy to understand.

luthfibalaka
Автор

just have to check from 2 to n/2 because any number greater than n/2 will not exactly divide n

VIVEKVARADARAJA
Автор

sir, please can you make a video on the fundamental rules of algorithm and flow chart

mitra
Автор

God bless you, you clarified a lot of things. thank you

Nexus
Автор

Thank you so much. This explains it very clearly

ricric
Автор

hi.sir i am having one question.can you please solve it.
1.write a java program to print fibonacci series in the given range.
2.write a java program to print largest odd fibonacci numbers in the given range.if odd fibonacci numbers does not exist in between then it should return 0.

AkashKumar-cqwv
Автор

Nice one, using English language makes your teaching understandable

festusnwauka
Автор

Thank you so much for sharing your knowledge, It help me out with mi code challenge

willhg
Автор

Ok good!
But this is a bit fundamental and does not need so much explanation.
Please do more dp, recursion, greedy and array manipulation algorithms

nands
Автор

in the second method, i should start with 2

madhuks