import java.util.Scanner; import java.math.BigInteger; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNextInt()) { int n = in.nextInt(); BigInteger fac_n = new BigInteger("1"); //n的阶乘(n!) for (int i = 2; i <= n; i++) //fac_n *= i; fac_n = fac_n.multiply(new BigInteger(String.valueOf(i))); BigInteger a = new BigInteger(in.next()); BigInteger a_k = new BigInteger("1"); //a^k(a的k次方) BigInteger zero = new BigInteger("0"); for (int k = 0;; k++) { BigInteger old_a_k = new BigInteger(a_k.toString()); //a^k a_k = a_k.multiply(a); //a^(k+1) if (fac_n.mod(old_a_k).equals(zero) && !fac_n.mod(a_k).equals(zero)) { //n! % a^k == 0 && n! % a^(k+1) != 0 System.out.println(k); break; } } } } }
import java.math.BigInteger; import java.util.Scanner; public class Main { public static void main(String[] args) { int n,a; Scanner sc = new Scanner(System.in); while(sc.hasNext()) { n = sc.nextInt(); a = sc.nextInt(); BigInteger num = BigInteger.ONE; for(int i = 2;i <= n;i ++) num = num.multiply(BigInteger.valueOf(i)); int t = 0; BigInteger d = BigInteger.valueOf(a); while(num.compareTo(BigInteger.ZERO) == 1 && num.mod(d).compareTo(BigInteger.ZERO) == 0) { t ++; num = num.divide(d); } System.out.println(t); } } }