Find n | Definition of findNumber function ; Finding x from equation n = x ( x + 1 ) / 2 + 1 ; Base of current block ; Value of n - th element ; Driver code
< ? php function findNumber ( $ n ) { $ x = floor ( ( -1 + sqrt ( 1 + 8 * $ n - 8 ) ) / 2 ) ; $ base = ( $ x * ( $ x + 1 ) ) / 2 + 1 ; return $ n - $ base + 1 ; } $ n = 55 ; echo findNumber ( $ n ) ; ? >