Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <ctime>
  5. #include <set>
  6. #include <map>
  7. #include <vector>
  8. #include <algorithm>
  9. #include <cmath>
  10. #include <cstring>
  11. #include <windows.h>
  12.  
  13. using namespace std;
  14.  
  15. #define ll long long
  16. #define lld long double
  17.  
  18. ll n, res;
  19.  
  20. ll fp(ll a, ll b)
  21. {
  22.     ll res = 1;
  23.     while (b)
  24.         if (b & 1)
  25.         {
  26.             if ((n + a - 1) / a > res)
  27.                 res *= a;
  28.             else
  29.                 res = n;
  30.             --b;
  31.         }
  32.         else
  33.         {
  34.             if ((n + a - 1) / a > a)
  35.                 a *= a;
  36.             else
  37.                 a = n;
  38.             b >>= 1;
  39.         }
  40.         return res;
  41. }
  42.  
  43. int main()
  44. {
  45.     //freopen("in.txt", "r", stdin);
  46.     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  47.  
  48.     //cout << fp(10, 1);
  49.     cin >> n;
  50.  
  51.     for (ll a = 0; a <= 60; a++)
  52.     for (ll b = 0; b <= 60; b++)
  53.     for (ll c = 0; c <= 60; c++)
  54.     {
  55.         ll l = 0, r = n;
  56.         while (l < r - 1)
  57.         {
  58.             ll m = (l + r) / 2;
  59.             ll q = fp(m, a) + fp(m, b) + fp(m, c);
  60.             if (q > n) r = m;
  61.             else l = m;
  62.         }
  63.  
  64.         if (fp(l, a) + fp(l, b) + fp(l, c) == n) res++;
  65.     }
  66.  
  67.     cout << res;
  68.  
  69.     return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement