fork 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. int nn = n;
  12. int operations = 0;
  13. while (nn % 2 == 0) {
  14. nn /= 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. System.out.println(operations);
  31.  
  32. if (n == 1) {
  33. System.out.println(operations >= m ? operations : -1);
  34. } else {
  35. System.out.println(-1);
  36. }
  37. }
  38. }
  39. }
  40.  
Success #stdin #stdout 0.2s 45288KB
stdin
4
10 5
1 5
10 4
3 4
stdout
2
-1
0
-1
2
-1
1
-1