Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define task "CAU4"
- #include <iostream>
- #include <cstdio>
- #include <cmath>
- #include <algorithm>
- using namespace std;
- constexpr int N = 1e7 + 5;
- int n, cnt[N];
- pair<int, int> res[N];
- void Read()
- {
- cin >> n;
- }
- void Solve()
- {
- int ans(0);
- for (int i = 0; i * i <= n; ++i)
- for (int j = 0; j * j <= n - i * i; ++j)
- ++cnt[i * i + j * j];
- for (int i = 0; i * i <= n; ++i)
- for (int j = 0; j * j <= n - i * i; ++j)
- ans += cnt[n - i * i - j * j];
- cout << ans << "\n";
- }
- void Additional()
- {
- // Ta lấy một cặp số (i, j) đại diện cho (i * i + j * j)
- for (int i = 0; i * i <= n; ++i)
- for (int j = 0; j * j <= n - i * i; ++j)
- res[i * i + j * j] = {i, j};
- int a[4] = {-1, -1, -1, -1};
- // Ta có thể cho rằng i != j => i < j
- for (int i = 0; i * i <= n; ++i)
- for (int j = i + 1; j * j <= n - i * i; ++j)
- if (cnt[n - i * i - j * j])
- {
- a[0] = i;
- a[1] = j;
- a[2] = res[n - i * i - j * j].first;
- a[3] = res[n - i * i - j * j].second;
- goto done;
- }
- done:;
- if (a[0] == -1)
- {
- cout << "Vo nghiem";
- return;
- }
- int ans(0);
- do
- {
- for (int i = 0; i < 4; ++i)
- cout << a[i] << " ";
- cout << "\n";
- ++ans;
- if (ans == 4)
- break;
- } while (next_permutation(a, a + 4));
- }
- int32_t main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- if (fopen(task ".INP", "r"))
- {
- freopen(task ".INP", "r", stdin);
- freopen(task ".OUT", "w", stdout);
- }
- Read();
- Solve();
- Additional();
- }
Add Comment
Please, Sign In to add comment