Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class CFTS01E09A {
- private static long fact(long n) {
- return (n == 0) ? 1 : n * fact(n-1);
- }
- public static int solve(int n, int k) {
- long x = fact(n);
- int i = 0;
- int max = 0;
- while (Math.pow(k, i) <= x) {
- if (x % Math.pow(k, i) == 0)
- max = i;
- i++;
- }
- return max;
- }
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- int t = in.nextInt();
- int a[] = new int[t];
- for (int i = 0; i < t; i++) {
- int n = in.nextInt();
- int k = in.nextInt();
- a[i] = solve(n, k);
- }
- for (int q : a)
- System.out.println(q);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement