MohamedAbdel3al

C. Wonderful Number

Sep 27th, 2021 (edited)
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std ;
  4. #define sz(s) int(s.size())
  5. #define all(v) v.begin() , v.end()
  6. #define imin INT_MIN
  7. #define imax INT_MAX
  8. typedef long long ll ;
  9. #define Time cerr << "Time Taken: " << (float)clock() / CLOCKS_PER_SEC << " Secs" << "\n";
  10. #define all(s) s.begin(), s.end()
  11. #define cin(v) for (auto& i : v) cin >> i ;
  12. #define pb(x) push_back(x)
  13. #define getline(s) getline(cin >> ws, s)
  14.  
  15. void ABDEL3AL () {
  16. ios_base::sync_with_stdio(false); cin.tie(nullptr) , cout.tie(nullptr) ;
  17. #ifndef ONLINE_JUDGEt
  18. freopen("input.txt" , "r" , stdin) , freopen("output.txt" , "w" , stdout) ;
  19. #endif
  20. Time
  21. }
  22.  
  23. bool is_palindroom (string s) {
  24. int l = 0 , r = sz(s) - 1 ;
  25. while (l <= r) {
  26. if (s[l++] != s[r--]) return false ;
  27. }
  28. return true ;
  29. }
  30.  
  31. string bin_to_dec (int n) {
  32. string bin ;
  33. while (n) {
  34. bin += (n % 2 + '0') ;
  35. n /= 2 ;
  36. }
  37. reverse(all(bin)) ;
  38. return bin ;
  39. }
  40.  
  41. int main() {
  42. ABDEL3AL() ;
  43. ll n ; cin >> n , cout << (is_palindroom(bin_to_dec(n)) && n % 2 ? "YES" : "NO") ;
  44. return 0;
  45. }
  46.  
Add Comment
Please, Sign In to add comment