If I'm not wrong (if so - please correct me):
1) You are using variable i in a for loop
for i in range(0,t):
but in each pass you are resetting it to one:
i=1
2) After first pass of loop:
while n>0:
ans=ans+n%10
n=n/10
you are loosing value of n (after the loop it is equal to zero) - try to remember it in other variable, and restore it in next passes, otherwise in any next pass value of n is going to be zero, because you are setting it to:
n=n*i
3) I suppose that
i=i+1
should be indented, because now value of i is constant for all passes of the "flag" loop.
So the loop should look like this (I have changed i to j):
while flag!=1:
ans=0
n=n*j
c=n
while n>0:
ans=ans+n%10
n=n/10
if ans==k:
print c
flag=1
j=j+1