关于#BigInteger#的问题,请各位专家解答!(语言-java)

img


7可以得到2,但是5不行得到的是0.不知道哪里错了?其他的也试过有好多也不行,是哪里用错了吗?求指教!
代码:
import java.math.BigInteger;
import java.util.Scanner;

public class n的阶乘中a出现次数BigInteger {
public static void main(String [] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int i=0;i<t;i++) {

        int n=sc.nextInt();
        int a=sc.nextInt();
        int cout=0;
        BigInteger res=BigInteger.ONE;//1
        BigInteger temp=BigInteger.valueOf(10);//10
        
        //n的阶乘结果res
        for(int j=1;j<=n;j++) {
            res=res.multiply(BigInteger.valueOf(j));
        }
        System.out.println(res);
        
        while(res!=BigInteger.ZERO) {
            BigInteger b=res.mod(temp);
            System.out.println(b);
            if(b==BigInteger.valueOf(a)) {
                cout++;
            }
            res=res.divide(temp);
        }
        System.out.println(cout);
    }
    sc.close();
    

}

}

img

你这样用b==BigInteger.valueOf(a)

除非a的值为0,不然结果都不对
应该改为

b.equals(BigInteger.valueOf(a))

System.out.println(res);
这一行输出的res值对不对啊