Advertisement
elektronika

szybkie potegowanie

Oct 21st, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <iostream>
  2. #include <sstream>
  3.  
  4. using namespace std;
  5. string x;
  6.  
  7. int main()
  8. {
  9.     unsigned long long a, b;
  10.     cin>>b;
  11.     cin>>a;
  12.  
  13.     while (a!=0)
  14.     {
  15.         if (a%2==1)
  16.             x=x+'1';
  17.         else x=x+'0';
  18.         a/=2;
  19.     }
  20.  
  21.     unsigned long long wynik=1;
  22.     unsigned long long ptg=1;
  23.  
  24.     for (unsigned long long i=0; i<x.length(); i++)
  25.     {
  26.         unsigned long long pom=1;
  27.  
  28.         if (x[i]=='1')
  29.         {
  30.             for (unsigned long long j=1; j<=ptg; j++)
  31.                 pom*=b;
  32.  
  33.             wynik*=pom;
  34.         }
  35.         ptg*=2;
  36.     }
  37.  
  38.     cout<<wynik;
  39.  
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement