L4. Print all prime factors of a Number | Maths Playlist

preview_player
Показать описание


Рекомендации по теме
Комментарии
Автор

The optimal approach is so amazing. Thanks Striver for GOAT level stuff.

md.ualiurrahmanrahat
Автор

last solution was actually something i never came across has thought of it but never applied great vid

amCoder
Автор

understood
class Solution{
public:
N) {
vector<int> vec;
for(int i=2; i<=sqrt(N); i++)
{
if(N%i==0){
vec.push_back(i);
while(N%i == 0)
{
N/=i;
}
}
}
if(N!=1)vec.push_back(N);
return vec;
}
};

hardikpatel
Автор

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.

HarshvardhanSankpal
Автор

8:30- actual method
14:40 more optimised

batmanlovesjokerr
Автор

One after other video is uploading it is very much satisfying for the beginners😊..
Thanks a lot Striver Bhaiya ❤

mohammedraheel
Автор

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

anshgupta
Автор

Can you videos on your own dsa sheet string Question

Express
Автор

Time hi nahi mil reha h abhi...varana ek din me ye playlist khatam kar denge... Striver Jindabaad! 😂

udayshankar-ev
Автор

Can you please upload detailed video on strings....

kedarmalap
Автор

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define vint vector<int>
#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*i<=n; i+=2){
if(n%i==0){
factors.eb((int)i);
while(n%i==0) n/=i;
}
}
if(n>2) factors.eb(n);
return factors;
}

int main() {
int n; cin >> n;
vint v=primeFactors(n);
for(int itm: v){
cout << itm << endl;
}
}

x-dev-johndoe
Автор

Bhaiya string and recursion ka kya plan hai??

veerverma
Автор

I can't find the c++ code for the last method, please someone help!

prajjwaltripathi
Автор

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? 😢

sonix_plays
Автор

where can i get code of this video ....plz provide link if any....??

shivamdhiman
Автор

In last approach, why we are adding n in list if it's not equal to 1 without checking it's prime or not.

VikashPatel-sfub
Автор

did anyone understand the last 16 example which he give to try itself

AkOp-bfvm
Автор

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 ??

HarshvardhanSankpal
Автор

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?

wul_frik
Автор

But the final optimized approach doesn't work for some numbers like 6.

gauristar