Prime factorisation Using sieve

In this method can you explain me why we are reducing given number value to 1?

Please explain using example!

hello @div_yanshu07

where ? pls share the code that u r refrerring also mention the line number that u want me to explain


I have copied this code from gfg.

Here’s the article for your referral.
And check out line number 50 in the given code link. I don’t understand why we are reducing it’s value and waiting for it to get 1.

@div_yanshu07
image

evrytime we are dividing x with its smallest prime factor right?
so it is very obvious that value of x will reduce on each iteration and it will become 1 after few iterations which should be our stopping condition.
example-> 6
6-> 3 (after dividing by 2 ,becuase 2 is smallest prime factor of 6)
3->1 (after dividing by 3 because 3 is smallest prime factor of 3)
stop