egogoboy

Эволюция

Jul 16th, 2022
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. #include <string>
  5. #include <queue>
  6. using namespace std;
  7.  
  8. int main() {
  9.  
  10.     std::ifstream fin("input.txt");
  11.     std::ofstream fout("output.txt");
  12.  
  13.     int k;
  14.     long long v1, v2;
  15.     fin >> k >> v1 >> v2;
  16.     vector<vector<long long>> dad(2);
  17.  
  18.     while (v1 > 1 || v2 > 1) {
  19.  
  20.         v1 /= 2;
  21.         if (v1 != 0)
  22.             dad[0].push_back(v1);
  23.        
  24.         v2 /= 2;
  25.         if (v2 != 0)
  26.             dad[1].push_back(v2);
  27.  
  28.     }
  29.  
  30.     long long max = 0;
  31.     for (int i = dad[0].size() - 1; i >= 0; --i) {
  32.         for (int j = dad[1].size() - 1; j >= 0; --j) {
  33.             if (dad[0][i] == dad[1][j]) {
  34.                 max = dad[0][i];
  35.             }
  36.         }
  37.     }
  38.  
  39.     fout << max;
  40.    
  41.     return 0;
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment