kayyam triangle implementation