Advertisement
artemgf

Копирование (цикл)

Mar 17th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <string>
  4. #include <set>
  5. #include <map>
  6. #include <algorithm>
  7. #include <string>
  8. #include <math.h>
  9. #include <vector>
  10.  
  11. using namespace std;
  12.  
  13. int sqrtfind(int n, int t)
  14. {
  15.     int prom;
  16.     prom = n;
  17.     while (prom !=1)
  18.     {
  19.         prom = prom / 2;
  20.         t++;
  21.     }
  22.    
  23.     return t;
  24. }
  25.  
  26. void powfind(long long k, long long n, long long prom, long long i)
  27. {
  28.     while (prom < n)
  29.         if (prom <= k)
  30.         {
  31.             prom = prom * 2;
  32.             i++;
  33.         }
  34.         else
  35.         {
  36.             if (((n - prom) % k) * 10 != 0)
  37.             {
  38.                 cout << i + (n - prom) / k + 1;
  39.                 return;
  40.             }
  41.             else
  42.             {
  43.                 cout << i + (n - prom) / k;
  44.                 return;
  45.             }
  46.         }
  47.     cout << i;
  48. }
  49.  
  50. int main()
  51. {
  52.     long long n, k, hours = 0;
  53.  
  54.     cin >> n >> k;
  55.  
  56.     if (n <= k)
  57.         if (n % 2 * 10 != 0)
  58.             cout << sqrtfind(n, 0) + 1;
  59.         else
  60.             cout << sqrtfind(n, 0);
  61.     else
  62.     {
  63.         powfind(k, n, 1, 0);
  64.     }
  65.  
  66.     _getch();
  67.     return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement