Advertisement
Guest User

Untitled

a guest
Jun 13th, 2015
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. /*****************************************************************************
  2.  * codeforces:   knst
  3.  * topcoder:     knstqq
  4.  * projecteuler: knstqq
  5.  * **************************************************************************/
  6.  
  7. #include <algorithm>
  8. #include <chrono>
  9. #include <iostream>
  10. #include <limits>
  11. #include <map>
  12. #include <set>
  13. #include <stack>
  14. #include <queue>
  15. #include <vector>
  16.  
  17. using namespace std;
  18. int test(int64_t l) {
  19.     int result = 0;
  20.     int64_t l2 = l * l;
  21.     static map<int64_t, int> m;
  22.     if (m.find(l) != m.end())
  23.         return m[l];
  24.     int64_t y = l;
  25.     for (int64_t x = 1; x * x < l2; ++x) {
  26.         while (x * x + y * y > l2)
  27.             --y;
  28.         if (y < x)
  29.             break;
  30.         if (y * y + x * x == l2) {
  31.             result = max(result, test(x) + 1);
  32.             result = max(result, test(y) + 1);
  33.         }
  34.     }
  35.     m[l] = result;
  36.     return result;
  37. }
  38.  
  39. int main() {
  40.     std::ios_base::sync_with_stdio(false);
  41.     cin.tie(0);
  42.  
  43.     int l;
  44.     cin >> l;
  45.  
  46.         int result = test(l);
  47.  
  48.         cout << result  << endl;
  49.  
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement