#include <map> #include <string> #include <vector> #include <algorithm> #include <iostream> #include <cmath> #include <iomanip> #include <set> #include <unordered_set> #define M_PI 3.14159265358979323846 #define ull unsigned long long #define ll long long #define vi vector<int> #define vll vector<long long> #define vull vector<unsigned long long> #define ld long double #define pii pair<int,int> #define pll pair<long long, long long> #define vvi vector<vector<int>> using namespace std; map<int, vector<int>> divs; vector<int> divisors(int n) { if (divs.find(n) != divs.end()) { return divs[n]; } int div = 1; vector<int> res; while (div * div <= n) { if (n % div == 0) { res.push_back(div); if (n / div != div) { res.push_back(n / div); } } div++; } divs[n] = res; return res; } ll doit(int n) { ll res = 0; vector<int> rest = divisors(n); for (auto d : rest) { if (d != 1 && d != n) { int d1 = d; int d2 = n/ d1 - 1; if (d2 > 1) { res++; } } } return res; } int main() { int n; cin >> n; ll result = 0; vector<int> rest = divisors(n); for (auto d : rest) { result += doit(n / d - 1); } cout << result; }
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 | #include <map> #include <string> #include <vector> #include <algorithm> #include <iostream> #include <cmath> #include <iomanip> #include <set> #include <unordered_set> #define M_PI 3.14159265358979323846 #define ull unsigned long long #define ll long long #define vi vector<int> #define vll vector<long long> #define vull vector<unsigned long long> #define ld long double #define pii pair<int,int> #define pll pair<long long, long long> #define vvi vector<vector<int>> using namespace std; map<int, vector<int>> divs; vector<int> divisors(int n) { if (divs.find(n) != divs.end()) { return divs[n]; } int div = 1; vector<int> res; while (div * div <= n) { if (n % div == 0) { res.push_back(div); if (n / div != div) { res.push_back(n / div); } } div++; } divs[n] = res; return res; } ll doit(int n) { ll res = 0; vector<int> rest = divisors(n); for (auto d : rest) { if (d != 1 && d != n) { int d1 = d; int d2 = n/ d1 - 1; if (d2 > 1) { res++; } } } return res; } int main() { int n; cin >> n; ll result = 0; vector<int> rest = divisors(n); for (auto d : rest) { result += doit(n / d - 1); } cout << result; } |