Loading...
Submission
Id When Author Problem Language CPU Memory Verdict
16912 2024-04-23 00:33:56 zunayed Binary Prime C++ 17 45 ms 3596 kb Accepted
Test Cases
CPU Memory Verdict
1 45 ms 3464 kb Accepted
2 45 ms 3520 kb Accepted
3 45 ms 3400 kb Accepted
4 45 ms 3392 kb Accepted
5 45 ms 3596 kb Accepted
6 45 ms 3580 kb Accepted
7 45 ms 3516 kb Accepted
8 45 ms 3552 kb Accepted
9 45 ms 3476 kb Accepted
10 45 ms 3444 kb Accepted
11 45 ms 3548 kb Accepted
Source Code
program.cpp
Download
  1. /* ...Bismillahir Rahmanir Raheem... */
  2.  
  3. /*
  4. Problem: binary_prime
  5. Date: 2024-Apr-23
  6. */
  7. #include<bits/stdc++.h>
  8. using namespace std;
  9. #define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  10. #define all(a) (a).begin(),(a).end()
  11. #define nl cout<<'\n' ;
  12. #define out(a) cout<<a<<'\n';
  13. #define hmm(ok) cout<<(ok==1?"YES":"NO")<<'\n';
  14. #define ld long double
  15. #define ll long long
  16. #define ull unsigned long long
  17. const ld PI = 3.141592653589793238462;
  18. const ll MOD = 1e9+7;
  19. const ll INF = 1e18;
  20. const int N=1e6;
  21. vector<bool>prime(N+1,true);
  22.  
  23.  
  24. void sieve() {
  25. for (ll p = 2; p * p <= N; p++) {
  26. if (prime[p]) {
  27. for (ll i = p * p; i <= N; i += p)
  28. prime[i] = false;
  29. }
  30. }
  31. }
  32.  
  33. void solve()
  34. {
  35. ll n;
  36. cin>>n;
  37. bitset<64>keep(n);
  38. int cnt=0;
  39. for(int i=0;n>0;i++){
  40. cnt += n%2;
  41. n = n/2;
  42. }
  43. if(prime[cnt] and cnt!=1)
  44. {
  45. out("Binary prime");
  46. }
  47. else{
  48. out(-1)
  49. }
  50. }
  51.  
  52.  
  53. int main()
  54. {
  55. faster;
  56. sieve();
  57. int test;
  58. cin>>test;
  59. int i=1;
  60. while(test--){
  61. solve();
  62. //cout<<"Case "<<i++<<":";
  63. }
  64. }