Loading...
Submission
# When Author Problem Language CPU Memory
20874 2024-06-13 22:24:21 AHAMMED_99 Binary Prime C 0 ms 1452 kb Accepted
Test Cases
# CPU Memory Points
1 0 ms 1452 kb 1 Accepted
2 0 ms 1440 kb 1 Accepted
3 0 ms 1344 kb 1 Accepted
4 0 ms 1332 kb 1 Accepted
5 0 ms 1340 kb 1 Accepted
6 0 ms 1420 kb 1 Accepted
7 0 ms 1428 kb 1 Accepted
8 0 ms 1344 kb 1 Accepted
9 0 ms 1344 kb 1 Accepted
10 0 ms 1332 kb 1 Accepted
11 0 ms 1336 kb 1 Accepted
Source Code
  1. #include <stdio.h>
  2. #include <stdbool.h>
  3.  
  4. // Function to check if a number is prime
  5. bool isPrime(int n) {
  6. if (n <= 1) return false;
  7. if (n == 2 || n == 3) return true;
  8. if (n % 2 == 0 || n % 3 == 0) return false;
  9.  
  10. // Check for factors from 5 to sqrt(n) with step 6
  11. for (int i = 5; i * i <= n; i += 6) {
  12. if (n % i == 0 || n % (i + 2) == 0)
  13. return false;
  14. }
  15. return true;
  16. }
  17.  
  18. // Function to count set bits in a number
  19. int countSetBits(unsigned long long n) {
  20. int count = 0;
  21. while (n) {
  22. n &= (n - 1);
  23. count++;
  24. }
  25. return count;
  26. }
  27.  
  28. int main() {
  29. int T;
  30. scanf("%d", &T);
  31.  
  32. while (T--) {
  33. unsigned long long N;
  34. scanf("%llu", &N);
  35.  
  36. int setBits = countSetBits(N);
  37.  
  38. if (isPrime(setBits))
  39. printf("Binary prime\n");
  40. else
  41. printf("-1\n");
  42. }
  43.  
  44. return 0;
  45. }
  46.