One test case failed in Manmohan Loves Pattern-I

Help needed, code given below

your logic will not work for bigger test cases
instead you can think of some logic of prime numbers(i.e if the present row is a prime number then what should be the pattern or when it is not prime then what should be the pattern)
you can refer this for your reference only https://ide.codingblocks.com/s/91165