191787 | CodeChef

how should be logic for this problem??