Advertisement
AlejandroGY

Untitled

Mar 28th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <cstdint>
  4. #include <algorithm>
  5. #include <string>
  6.  
  7. std::string to_string(__uint128_t n) {
  8.    std::string res;
  9.    do {
  10.       res += '0' + n % 10;
  11.       n /= 10;
  12.    } while (n != 0);
  13.  
  14.    std::reverse(res.begin( ), res.end( ));
  15.    return res;
  16. }
  17.  
  18. __uint128_t exp(__uint128_t a, __uint128_t n) {
  19.     __uint128_t res = 1;
  20.     for (; n; n >>= 1) {
  21.         if (n & 1) {
  22.             res *= a;
  23.         }
  24.         a *= a;
  25.     }
  26.     return res;
  27. }
  28.  
  29. int main( ) {
  30.     uint64_t a, b;
  31.     std::cin >> a >> b;
  32.  
  33.     __uint128_t n = exp(a, b);
  34.     n = floor(log10(n)) + 1;
  35.  
  36.     std::cout << to_string(n);
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement