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();
}
}
你这样用b==BigInteger.valueOf(a)
除非a的值为0,不然结果都不对
应该改为
b.equals(BigInteger.valueOf(a))
System.out.println(res);
这一行输出的res值对不对啊