Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- bool GetPartition(int n, vector<int> &partition) {
- if (n == 0 && partition.size() <= 4) {
- return true;
- }
- if (n > 0 && partition.size() == 4) {
- return false;
- }
- for (int i = 1; i * i <= n; ++i) {
- partition.push_back(i);
- if (GetPartition(n - i * i, partition)) {
- return true;
- }
- partition.pop_back();
- }
- return false;
- }
- int main() {
- int n;
- cin >> n;
- vector<int> partition;
- bool ans = GetPartition(n, partition);
- for (auto el: partition) {
- cout << el << " ";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement