Can you please discuss how you found the equation sum = (sqrt(1+8*n)-1)/2 ?
suppose, n=3then,c=sqrt(1+8*3);x=c-1;y=x/2;printf("%lld",y);
How you got this equation?
imple math problemn*(n+1)/2 = sn^2+n=2*sn^2+n+(-2*s)=0Using quadratic equation ax^2+bx+c=0del = sqrt(b*b-4*a*c) = sqrt(1-4*1*(-2s)) = sqrt(1+8s)we know x = (-b(+-) del)/2aHere i use only + value because del is always positiveso n = (-1+sqrt(1+8s))/2Input as double sthen print n (where n is convert from double to lo
Can you please discuss how you found the equation sum = (sqrt(1+8*n)-1)/2 ?
ReplyDeletesuppose, n=3
Deletethen,
c=sqrt(1+8*3);
x=c-1;
y=x/2;
printf("%lld",y);
Can you please discuss how you found the equation sum = (sqrt(1+8*n)-1)/2 ?
ReplyDeleteHow you got this equation?
ReplyDeleteimple math problem
ReplyDeleten*(n+1)/2 = s
n^2+n=2*s
n^2+n+(-2*s)=0
Using quadratic equation ax^2+bx+c=0
del = sqrt(b*b-4*a*c) = sqrt(1-4*1*(-2s)) = sqrt(1+8s)
we know x = (-b(+-) del)/2a
Here i use only + value because del is always positive
so n = (-1+sqrt(1+8s))/2
Input as double s
then print n (where n is convert from double to lo