All pastes #2035052 Raw Edit

dpecka

public text v1 · immutable
#2035052 ·published 2010-12-31 13:06 UTC
rendered paste body
/* sample example: `gcc -o foo bar -lm`*	having inane equation n(n+sqrt(n))=L where:*	n increments as m=1; n=(++m)**2 .. so only integers are used*	the highest value of sqrt(n) is FF (255) so n could be up to 255**2**	you're getting L and need to determine n*	in example below we increment n and break() until we reach equality with L**	well, this code uses linear search which is NOT definitely very optimal*	foo() also requires that only correct L will be passed ..*/#include <stdio.h>#include <math.h>#include <stdlib.h>long foo(long long L){	long m, n, e;	m = n = 1;	e = pow(255, 2);		for(n = 1; n <= e; n = pow(++m, 2)) {		if(n * (n + sqrt(n)) == L)			break;	};	return(n);}int main(void){	printf("%ld\n", foo(2439853704)); /* L value is hardcoded here .. */	exit(0);}