Piyush and magical brick

this is my code https://ide.codingblocks.com/s/247052

none of the test cases are correct.
kindly help me out