Please explain how to calculate sum of divisors of any number
Please explain how to calculate sum of divisors of any number
Hi
are u aware of finding divisors of a number?
u can either do it in O(N) time
by simply iterating from 1 to n and checking if n%i == 0
if so add i to sum variable and u get the sum of divisors
for (int i = 1 ; i <= n ; i++){
if(num%i == 0) sum+= i;
}
or else do it in O(sqrt N)
`for` `(` `int` `i=1; i<=` `sqrt` `(n); i++) `
` ` `{ `
` ` `if` `(n%i == 0) `
` ` `{ `
` ` `// If divisors are equal, print only one `
` ` `if` `(n/i == i) `
` ` `printf` `(` `"%d "` `, i); `
` `
` ` `else` `// Otherwise print both `
` ` `printf` `(` `"%d %d "` `, i, n/i); `
` ` `} `
` ` `} `
Hey,can you please explain in that method where complexity isO(log(n)),the method that we discussed in above video(prime seive method).Prateek bhaiya told that we will use GP for calculating it.Please explain that method
see did u understand the p&c method
factors are 2^3 , 3 ^1 , 5 ^ 1
so sum of all factors nikalna h
kyuki hum geometric progression dikh raha h to usme
iska second solution dekh lo
thank u so much,i got it
1 Like