December Lunchtime GuessNumber

hey!.. my code is showing run time error for task with original constraints
plz tell what changes should i make to score full here … i only got partial markings for the same

Scanner s  = new Scanner(System.in);
	
	int t = s.nextInt();
	while (t-- >0){
	    long a = s.nextInt();
	    long m = s.nextInt();
	    ArrayList<Integer> arrLL = new ArrayList<>();
	    ArrayList<Integer> newarrLL = new ArrayList<>();
	    
	    for (int i =1 ; i<= Math.sqrt(m); i++){
	        if (m%i == 0){
	        if (m/i == i){
	            arrLL.add(i);   
	        }
	        else{
	            arrLL.add(i);
	            arrLL.add((int)(m/i));
	        }
	        }
	    }
	    
	  
	    int count = 0;
	    for (int f : arrLL){  // f  = factors
	     //   System.out.println(f);
	        if ((f-1)%a == 0){
	            int q = (f-1)/(int)a;
	            int d = (int)m/f;
	            int n = q*d;
	       
	        if (n != 0 ){
	        newarrLL.add(n);
	        count ++;
	        }
	        }
	    }
	    
	    System.out.println(count);
	    Collections.sort(newarrLL);
	    for (int i: newarrLL){
	        System.out.print(i+" ");
	    }
	    System.out.println();
	}