Advertisement
smatskevich

Seminar4

Jan 10th, 2022
839
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.99 KB | None | 0 0
  1. #include <algorithm>
  2. #include <deque>
  3. #include <iostream>
  4. #include <map>
  5. #include <set>
  6. #include <string>
  7. #include <tuple>
  8. #include <unordered_map>
  9. #include <unordered_set>
  10. #include <vector>
  11.  
  12. typedef long long ll;
  13. typedef unsigned long long ull;
  14. using namespace std;
  15.  
  16. // Максимальная степень 2, делящая n.
  17. int main1() {
  18.   ios::sync_with_stdio(false);
  19.   cin.tie(nullptr);
  20.  
  21.   ull n = 0;
  22.   cin >> n;
  23.   int power = 0;
  24.   while ((n & 1) == 0) {
  25.     ++power;
  26.     n >>= 1;
  27.   }
  28.   // Выводим 2^power
  29.   cout << (1 << power);
  30.  
  31.   return 0;
  32. }
  33.  
  34. // Битовое представление n.
  35. int main2() {
  36.   ios::sync_with_stdio(false);
  37.   cin.tie(nullptr);
  38.  
  39.   ll n = 0;
  40.   cin >> n;
  41.   for (int i = 0; i < 64; ++i) {
  42.     cout << ((n & 1) == 0 ? "0" : "1");
  43.     n >>= 1;
  44.   }
  45.   cout << endl;
  46.  
  47.   return 0;
  48. }
  49.  
  50. // Битовое представление n от старших к младшим.
  51. int main3() {
  52.   ios::sync_with_stdio(false);
  53.   cin.tie(nullptr);
  54.  
  55.   ll n = 0;
  56.   cin >> n;
  57.   for (int i = 63; i >= 0; --i) {
  58.     cout << ((n & (1ll << i)) == 0 ? "0" : "1");
  59.   }
  60.   cout << endl;
  61.  
  62.   return 0;
  63. }
  64.  
  65. // Представление числа в 5-ной СИ от старших к младшим.
  66. int main4() {
  67.   ios::sync_with_stdio(false);
  68.   cin.tie(nullptr);
  69.  
  70.   ll n = 0;
  71.   cin >> n;
  72.   vector<int> digits;
  73.   while (n != 0) {
  74.     digits.push_back(int(n % 5));
  75.     n /= 5;
  76.   }
  77.   reverse(digits.begin(), digits.end());
  78.   for (int d : digits) cout << d;
  79.   if (digits.empty()) cout << 0;
  80.   cout << endl;
  81.   return 0;
  82. }
  83.  
  84. // Представление числа в 5-ной СИ от старших к младшим.
  85. // Версия с деком.
  86. int main() {
  87.   ios::sync_with_stdio(false);
  88.   cin.tie(nullptr);
  89.  
  90.   ll n = 0;
  91.   cin >> n;
  92.   deque<int> digits;
  93.   while (n != 0) {
  94.     digits.push_front(int(n % 5));
  95.     n /= 5;
  96.   }
  97.   for (int d : digits) cout << d;
  98.   if (digits.empty()) cout << 0;
  99.   cout << endl;
  100.   return 0;
  101. }
  102.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement