#python #12 🔥 Prime Number in Python 🔥 | Python Pattern Programming | #shorts #coding #beginners

preview_player
Показать описание
In this video, I have shared how to check primer number in python programming. Keep learning using all my videos and become master in the coding.
Рекомендации по теме
Комментарии
Автор

The way i do it for super fast is (note that i use c++ but this is an example):
If (n < 2) return flase
If (n % 2 == 0 && n>2 ) return false
For(int i = 3; i*i<=n; i +=2) if(n%i == 0) return false;
Rerurn true;
Wath i did is test if n is smaller than 2, cuz any number smaller is not prime, then if the number is dividible by 2 from the start and then test if it has divizors by going from 3 to its square root whitch us like a middle poit for the divizors of any number and skip the even numbers cuz its mutch more efficent amd if it didnt found any the number is prime, so in the worst case we perform square root of n operations so its a efficency of O(square root n)

cosmq
visit shbcf.ru