Advertisement
artemgf

Копирование (рекурсия)

Mar 17th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 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.     if (prom != 1)
  18.     {
  19.         prom = prom / 2;
  20.         t++;
  21.         sqrtfind(prom, t);
  22.     }
  23.     else
  24.         return t;
  25. }
  26.  
  27. void powfind(long long k, long long n, long long prom, long long i)
  28. {
  29.     if (prom < n)
  30.         if (prom <= k)
  31.         {
  32.             prom = prom * 2;
  33.             i++;
  34.             powfind(k, n, prom, i);
  35.         }
  36.         else
  37.         {
  38.             if (((n - prom) % k) * 10 != 0)
  39.                 cout << i + (n - prom) / k + 1;
  40.             else
  41.                 cout << i + (n - prom) / k;
  42.         }
  43.     else
  44.             cout << i;
  45. }
  46.  
  47. int main()
  48. {
  49.     long long n, k, hours = 0;
  50.  
  51.     cin >> n >> k;
  52.  
  53.     if (n <= k)
  54.         if (n % 2 * 10 != 0)
  55.             cout << sqrtfind(n, 0) + 1;
  56.         else
  57.             cout << sqrtfind(n, 0);
  58.     else
  59.     {
  60.         powfind(k, n, 1, 0);
  61.     }
  62.  
  63.     _getch();
  64.     return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement