fork(1) download
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6. int t = scanner.nextInt();
  7.  
  8. for (int i = 0; i < t; i++) {
  9. int n = scanner.nextInt();
  10. int m = scanner.nextInt();
  11.  
  12. int operations = 0;
  13. while (n % 2 == 0) {
  14. n /= 2;
  15. operations++;
  16. }
  17.  
  18. int j = 3;
  19. while (j * j <= n) {
  20. while (n % j == 0) {
  21. n /= j;
  22. operations++;
  23. }
  24. j += 2;
  25. }
  26.  
  27. if (n > 2) {
  28. operations++;
  29. }
  30.  
  31. if (n == 1) {
  32. System.out.println(operations >= m ? operations : -1);
  33. } else {
  34. System.out.println(-1);
  35. }
  36. }
  37. }
  38. }
  39.  
Success #stdin #stdout 0.14s 35228KB
stdin
4
10 5
1 5
10 4
3 4
stdout
-1
-1
-1
-1