D1: Getting wa

,

import java.io.*;

public class Main {

public static void main(String[] args) throws IOException {
    
            
   long[] sb=new long[500001];
   int[] flag=new int[500001];
   
   for(int k=1;k<=707;k++){ int q=k;
        for(int l=q*q;l<500001;l+=q){
            if(k==1)
                sb[l]=1;
            sb[l]*=q;
            flag[l]++;
            if(q!=l/q && q!=1){
                sb[l]*=(l/q);
            
          }    
            if(sb[l]>9999)
                sb[l]%=10000;
        }                    
    }
      
         
   

    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    int n=Integer.parseInt(br.readLine());
    StringBuilder st=new StringBuilder();
    while(n--!=0){
    long count;
    int k=Integer.parseInt(br.readLine());             
    
    if(k==1)
        count=1;
    else if(sb[k]==0&&flag[k]==1)
        count=1;
    else
    {
        count=sb[k];
        
    }
    
    if(count<10)
        st.append("000");
    if(count<100&&count>9)
        st.append("00");
    if(count>99&&count<1000)
        st.append("0");
                             
            
    st.append(count).append("\n");

    }
    System.out.println(st);

}

}

I don’t really understand for the problem code D1 what is my above code not handling. Its getting a wrong answer not a TLE. So its fast enough but I’m not handling a certain case i suppose but I dunno what exactly. Can anyone help?

//