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(); // Number of test cases
  7.  
  8. for (int i = 0; i < t; i++) {
  9. int n = scanner.nextInt(); // Input number
  10. boolean isPossible = canBeRepresentedAsProduct(n);
  11. System.out.println(isPossible ? "YES" : "NO");
  12. }
  13.  
  14. scanner.close();
  15. }
  16.  
  17. // Function to check if a number can be represented as a product of binary decimals
  18. private static boolean canBeRepresentedAsProduct(int n) {
  19. if (n == 1) {
  20. return true; // 1 is already a binary decimal
  21. }
  22.  
  23. // Check divisibility by numbers from 2 to sqrt(n)
  24. for (int i = 2; i * i <= n; i++) {
  25. if (n % i == 0) {
  26. // If n is divisible by i, check if i is a binary decimal
  27. while (n % i == 0) {
  28. n /= i;
  29. }
  30. // If n becomes 1, i is a binary decimal and n can be represented as a product
  31. if (n == 1) {
  32. return true;
  33. }
  34. }
  35. }
  36.  
  37. return false; // n cannot be represented as a product of binary decimals
  38. }
  39. }
  40.  
Success #stdin #stdout 0.14s 56644KB
stdin
11
121
1
14641
12221
10110
100000
99
112
2024
12421
1001
stdout
YES
YES
YES
NO
NO
YES
NO
NO
NO
NO
NO