L4. Print all prime factors of a Number | Maths Playlist
HTML-код
- Опубликовано: 1 окт 2024
- Notes/Codes/Problem links under day 8 of A2Z DSA Course: takeuforward.o...
Entire playlist: • Maths Playlist | Langu...
Follow us on our other social media handles: linktr.ee/take...
The optimal approach is so amazing. Thanks Striver for GOAT level stuff.
Its ok bro check out TUF+
You are the GOAT In DSA on youtube
That I am ☺
#include
using namespace std;
#define ll long long
#define vint vector
#define eb emplace_back
vint primeFactors(int n){
vint factors;
if(n%2==0){
factors.eb(2);
n/=(n & -n);
}
for(ll i=3; i*i2) factors.eb(n);
return factors;
}
int main() {
int n; cin >> n;
vint v=primeFactors(n);
for(int itm: v){
cout
Can anyone tell me in the most optimal solution why we go only to the root n times? Like what is the intuition behind it? 😢
you want to find the prime factors so for example 1600 sq.root(1600) == 40 now 41 is just greater than 40 and also a prime number but 41^2 >1600 and also 39 just lesser than 40 , 39^2
last solution was actually something i never came across has thought of it but never applied great vid
Its ok bro check out TUF+
where can i get code of this video ....plz provide link if any....??
for number like 37 ,n stilll remains 37 which is a factor ,so we add and in case of 16 ,n reduces to 1 ,so we dont need to add it to list ,that;s why n!=1 then add to list
I have a doubt, why can't multiple prime numbers be there after the loop ends, like after the for loop ends, the number might be something like p1 * p2, where p1 and p2 are primes?
If n = 221.
Then i * i
Can you videos on your own dsa sheet string Question
Time hi nahi mil reha h abhi...varana ek din me ye playlist khatam kar denge... Striver Jindabaad! 😂
did anyone understand the last 16 example which he give to try itself
n = 16.
(1) i = 2
i*i = 4 < 16
16 % 2 = 0 .
list.add(2)
while(n % 2 == 0) {
16/2 = 8
8/2 = 4
4/2 = 2
2/2 = 1.
}
Now while loop break.
i is become 3 and n is become 1.
3 * 3 = 9 < 1 ❌ so condition false
So for loop break.
And now check if n != 1
n = 1 and 1 = 1 so condition false ❌
And final ans
list = [2]
@@vipuljamod4119 thnx bro
Can you please upload detailed video on strings....
Understood......Thank You So Much for this wonderful video......🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
Its ok bro check out TUF+
Thanks a lot :)
Plz complete remaining sheet as well
God of dsa and cp
understood
class Solution{
public:
vectorAllPrimeFactors(int N) {
vector vec;
for(int i=2; i
One after other video is uploading it is very much satisfying for the beginners😊..
Thanks a lot Striver Bhaiya ❤
Its ok bro check out TUF+
Bhaiya string and recursion ka kya plan hai??
aditya verma se pdhle recursion bhot mst hai uska
@@es_amit phir lekin sequence toot jayega, ab dekhta hoon agar thode din tak nhi kiya post toh kahi or se he krna padega
@@veerverma5586 bhai ek baar pdh ke toh dekh fir btaio (recursion) Aditya verma se. mera recursion bhot weak tha phle ab dp ke questions bde aaram se solve kr deta hu
@@es_amit ohh 😮, yeh he hai kya 19 videos wala?
@@veerverma5586 ha Bhai aaram se dekh fir btaio mujhe kaisi lgi, backtracking ki bhi dekh lio
I can't find the c++ code for the last method, please someone help!
for solving the edge case of 37, cant we simpliy check if n is prime, if yes, we know theres only 1 pime factor that is itself ??
consider for 35
12:30 in this code we need to also apply isPrime( i ) in the if statement, else we are blindly adding also the divisors, but the question demands prime divisors.
no you are wrong. for example,2 is a prime number. when 2 divdes the number as many times as possible then 2 mutiples cannot divide the number. similarly for 3 etc.
Amazing done and dusted
In last approach, why we are adding n in list if it's not equal to 1 without checking it's prime or not.
Considering worst case of factors of primes of number can go upto number. So, we are considering total spaces upto the numbers.
See If there is the value Of N which is prime then we are iterating i upto sqrt N so we will not reach to the N through i but we know that if n is not 1 then it will also be the factor so we will add it to the answer see dry run the code for 65 then you will understand
8:30- actual method
14:40 more optimised
understood
understood
understood
US!
Understood!
💖💖💖
Nhi karna print bhai... Kyu paresan kr rha h. Job dega to bol
tujhe toh waise v koi job na de🤣🤡
@@priyanshubiswas9396 🤣🤣🤣🤣
understood
First view
First view ❤
Understood. thanks
Thank you very much
Understood ❤
Bit Manipulation is better taught by Luv
But the final optimized approach doesn't work for some numbers like 6.
public static ArrayList primeFactor(int n) {
ArrayList al = new ArrayList();
for(int i=2; i * i
Try this code.., this working perfectly.
Yes bro @@vipuljamod4119