Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- std::string to_binary_string( int n)
- {
- std::string result;
- do
- {
- result += ('0' + (n % 2));
- n = n / 2;
- } while (n > 0);
- return result;
- }
- int step(std::string chislo, int x)
- {
- int i = chislo.size()-1;
- int res=1;
- while (chislo[i])
- {
- if (chislo[i] == 0)continue;
- if (chislo[i] == 1)res += x * chislo[i];
- res *= res;
- i--;
- }
- return res;
- }
- int main()
- {
- int chislo, step;
- std::cout << "Vvedite chislo" << std::endl;
- std::cin >> chislo;
- std::cout << "vvedite step" << std::endl;
- std::cin >> step;
- std::cout << "Vi vveli\t" << chislo << "i step\t" << step << std::endl;
- std::string d=to_binary_string(step);
- std::cout<< step(d, chislo);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement