P 1591階乗デジタル---java
10020 ワード
n!n!n! 。
t(t≤10)t(t \leq 10)t(t≤10), 。 ttt , n(n≤1000)n(n \leq 1000)n(n≤1000) aaa。
, , n!n!n! aaa 。
#1
2
5 2
7 0
#1
1
2
import java.math.BigDecimal;
import java.util.Scanner;
public class p1591 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
int n[] = new int[t];
int a[] = new int[t];
for (int i = 0; i < t; i++) {
n[i]=sc.nextInt();
a[i] = sc.nextInt();
}
sc.close();
int count = 0;
for (int i = 0; i < t; i++) {
//System.out.println(f(n[i]));
BigDecimal num1 = new BigDecimal(String.valueOf(f(n[i])));
String s1 = num1.toString();
for (int j = 0; j < s1.length(); j++) {
int b = s1.charAt(j)-48;//ASCALL 48 1
if (b==a[i])
count++;
}
System.out.println(count);
count=0;//count 0
}
}
public static BigDecimal f(int n){
// ,
BigDecimal sum=new BigDecimal("1");
for (int i = 1; i <= n; i++) {
sum = sum.multiply(BigDecimal.valueOf(i));
}
return sum;
}
}