Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*****************************************************************************
- * codeforces: knst
- * topcoder: knstqq
- * projecteuler: knstqq
- * **************************************************************************/
- #include <algorithm>
- #include <chrono>
- #include <iostream>
- #include <limits>
- #include <map>
- #include <set>
- #include <stack>
- #include <queue>
- #include <vector>
- using namespace std;
- int test(int64_t l) {
- int result = 0;
- int64_t l2 = l * l;
- static map<int64_t, int> m;
- if (m.find(l) != m.end())
- return m[l];
- int64_t y = l;
- for (int64_t x = 1; x * x < l2; ++x) {
- while (x * x + y * y > l2)
- --y;
- if (y < x)
- break;
- if (y * y + x * x == l2) {
- result = max(result, test(x) + 1);
- result = max(result, test(y) + 1);
- }
- }
- m[l] = result;
- return result;
- }
- int main() {
- std::ios_base::sync_with_stdio(false);
- cin.tie(0);
- int l;
- cin >> l;
- int result = test(l);
- cout << result << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement