#include <iostream> #include <vector> #include <cmath> using namespace std; vector<int> divisors(long n, bool one = true, long ltThan = -1) { vector<int> ret; //ret.clear(); if (ltThan == -1) ltThan = n/2; //sqrt(n) + 1; ret.reserve(ltThan); if (one) ret.push_back(1); for (int i = 2; i < sqrt(n); i++) if (n % i == 0) { if (i < ltThan) ret.push_back(i); auto x = n/i; if (x < ltThan) ret.push_back(x); } return ret; } int main() { long long n = 0; long long result = 0; cin >> n; for (auto const a : divisors(n, true, n/6+1)) { auto t = n / a - 1; //cout << t <<endl; for (int i = 2; i <= sqrt(t); i++) { if (t % i != 0) continue; { auto const b = a*i; auto const c = (t-i)*a; if ((a < b) && (b < c) && (a + b + c == n)) { result ++; //cout << a << " a< " << b << " < " << c << endl; } } { int i2 = t/i; if (i2 <= i) continue; auto const b = a*i2; auto const c = (t-i2)*a; if ((a < b) && (b < c) && (a + b + c == n)) { result ++; //cout << a << " b< " << b << " < " << c << endl; } } } //for (auto x : divisors(t, false, t/2)) //{ //result++; ////cout << a << " < " << a*x << " < " << (t-x)*a << endl; //} } cout << result; 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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | #include <iostream> #include <vector> #include <cmath> using namespace std; vector<int> divisors(long n, bool one = true, long ltThan = -1) { vector<int> ret; //ret.clear(); if (ltThan == -1) ltThan = n/2; //sqrt(n) + 1; ret.reserve(ltThan); if (one) ret.push_back(1); for (int i = 2; i < sqrt(n); i++) if (n % i == 0) { if (i < ltThan) ret.push_back(i); auto x = n/i; if (x < ltThan) ret.push_back(x); } return ret; } int main() { long long n = 0; long long result = 0; cin >> n; for (auto const a : divisors(n, true, n/6+1)) { auto t = n / a - 1; //cout << t <<endl; for (int i = 2; i <= sqrt(t); i++) { if (t % i != 0) continue; { auto const b = a*i; auto const c = (t-i)*a; if ((a < b) && (b < c) && (a + b + c == n)) { result ++; //cout << a << " a< " << b << " < " << c << endl; } } { int i2 = t/i; if (i2 <= i) continue; auto const b = a*i2; auto const c = (t-i2)*a; if ((a < b) && (b < c) && (a + b + c == n)) { result ++; //cout << a << " b< " << b << " < " << c << endl; } } } //for (auto x : divisors(t, false, t/2)) //{ //result++; ////cout << a << " < " << a*x << " < " << (t-x)*a << endl; //} } cout << result; return 0; } |