Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #include <iostream>
  2. std::string to_binary_string( int n)
  3. {
  4. std::string result;
  5. do
  6. {
  7. result += ('0' + (n % 2));
  8. n = n / 2;
  9. } while (n > 0);
  10. return result;
  11. }
  12.  
  13. int step(std::string chislo, int x)
  14. {
  15. int i = chislo.size()-1;
  16. int res=1;
  17. while (chislo[i])
  18. {
  19. if (chislo[i] == 0)continue;
  20. if (chislo[i] == 1)res += x * chislo[i];
  21. res *= res;
  22. i--;
  23. }
  24. return res;
  25. }
  26.  
  27.  
  28.  
  29.  
  30.  
  31. int main()
  32. {
  33. int chislo, step;
  34. std::cout << "Vvedite chislo" << std::endl;
  35. std::cin >> chislo;
  36. std::cout << "vvedite step" << std::endl;
  37. std::cin >> step;
  38. std::cout << "Vi vveli\t" << chislo << "i step\t" << step << std::endl;
  39. std::string d=to_binary_string(step);
  40. std::cout<< step(d, chislo);
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement