/* * Copyright (C) 2018 Paweł Widera * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details: * http://www.gnu.org/licenses/gpl.html */ #include <cmath> #include <vector> #include <iostream> #include <algorithm> using namespace std; vector<int> find_divisors(int n) { vector<int> divisors; for (int i = 1; i <= sqrt(n); ++i) { if (n % i == 0) { divisors.push_back(i); divisors.push_back(n / i); } } sort(divisors.begin(), divisors.end()); return divisors; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; int count = 0; cin >> n; vector<int> n_divisors = find_divisors(n); // count triplets for (auto a : n_divisors) { vector<int> divisors = find_divisors(n - a); for (auto b: divisors) { if (b <= a || b % a != 0) { continue; } int c = n - a - b; if (c > b && c % a == 0) { ++count; } } } cout << count << endl; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | /* * Copyright (C) 2018 Paweł Widera * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details: * http://www.gnu.org/licenses/gpl.html */ #include <cmath> #include <vector> #include <iostream> #include <algorithm> using namespace std; vector<int> find_divisors(int n) { vector<int> divisors; for (int i = 1; i <= sqrt(n); ++i) { if (n % i == 0) { divisors.push_back(i); divisors.push_back(n / i); } } sort(divisors.begin(), divisors.end()); return divisors; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; int count = 0; cin >> n; vector<int> n_divisors = find_divisors(n); // count triplets for (auto a : n_divisors) { vector<int> divisors = find_divisors(n - a); for (auto b: divisors) { if (b <= a || b % a != 0) { continue; } int c = n - a - b; if (c > b && c % a == 0) { ++count; } } } cout << count << endl; return 0; } |