#include <iostream> #include <vector> #include <cmath> #include <set> std::vector<long> getAllDivisions(long n, long start) { std::vector<long> result; for (long a = start; a<=std::sqrt(n); ++a) { if (n%a == 0) result.push_back(a); } return result; } std::vector<long> getAllDivisions(long n) { std::vector<long> result; for (long a = 1; a<=std::sqrt(n); ++a) { if (n%a == 0) { result.push_back(a); if (a != n/a) result.push_back(n/a); } } return result; } long countDiv(long n, long a, bool print = false) { long result = 0; std::set<long> uniq; for (long x : getAllDivisions(n,2)) { if (n/x >=3) { ++result; uniq.insert(x); if (print) std::cout << "a: " << a << " b: " << a*x << " c: " << a*x*(n/x - 1) << std::endl; } } for (long y : getAllDivisions(n,3)) { if (uniq.count(n/y)>0 || n/y<2) continue; ++result; long x = n/y; if (print) std::cout << "a: " << a << " b: " << a*x << " c: " << a*x*(y-1) << std::endl; } return result; } long new_pin(long n, bool print = false) { long count = 0; for (long a : getAllDivisions(n)) { long rem = n/a - 1; count += countDiv(rem, a, print); } return count; } int main() { long n = 1e9; std::cin >> n; std::cout << new_pin(n) << std::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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | #include <iostream> #include <vector> #include <cmath> #include <set> std::vector<long> getAllDivisions(long n, long start) { std::vector<long> result; for (long a = start; a<=std::sqrt(n); ++a) { if (n%a == 0) result.push_back(a); } return result; } std::vector<long> getAllDivisions(long n) { std::vector<long> result; for (long a = 1; a<=std::sqrt(n); ++a) { if (n%a == 0) { result.push_back(a); if (a != n/a) result.push_back(n/a); } } return result; } long countDiv(long n, long a, bool print = false) { long result = 0; std::set<long> uniq; for (long x : getAllDivisions(n,2)) { if (n/x >=3) { ++result; uniq.insert(x); if (print) std::cout << "a: " << a << " b: " << a*x << " c: " << a*x*(n/x - 1) << std::endl; } } for (long y : getAllDivisions(n,3)) { if (uniq.count(n/y)>0 || n/y<2) continue; ++result; long x = n/y; if (print) std::cout << "a: " << a << " b: " << a*x << " c: " << a*x*(y-1) << std::endl; } return result; } long new_pin(long n, bool print = false) { long count = 0; for (long a : getAllDivisions(n)) { long rem = n/a - 1; count += countDiv(rem, a, print); } return count; } int main() { long n = 1e9; std::cin >> n; std::cout << new_pin(n) << std::endl; return 0; } |