//by Michal Gilski #include <cstdlib> #include <cstdio> #include <vector> #include <deque> using namespace std; int ipow(int base, int exp) { int result = 1; for (;;) { if (exp & 1) result *= base; exp >>= 1; if (!exp) break; base *= base; } return result; } int czynnrekur(vector<pair<int,int> > &v, vector<int> &wyn, int k, int suma, int n) { if(k == v.size()) { if(suma != 1 && suma!=n) wyn.push_back(suma); return 0; } pair<int, int> p = v[k]; for (int i = 0; i <= p.second; ++i) { czynnrekur(v, wyn, k+1, suma * ipow(p.first, i), n); } } vector<pair<int,int> > czynniki_pierw (int a) { int k = 2; int l; vector<pair<int,int> > v; while(a > 1) { if (!(a%k)) { l = 0; while(!(a%k) && a > 1) { a/=k; l++; } if(k > 1)v.push_back(pair<int,int> (k,l)); } else k++; if(k*k > a) { if(a > 1)v.push_back(pair<int,int> (a,1)); break; } } return v; } vector<int> czynniki2(int a) { vector<pair<int,int> > v; v = czynniki_pierw(a); vector<int> w; czynnrekur(v, w, 0, 1, a); return w; } int main(int argc, char const *argv[]) { int n; scanf("%d", &n); vector<int> w; w = czynniki2(n); w.push_back(1); int a,k; int wynik = 0; for (int i = 0; i < w.size(); ++i) { a = w[i]; if (n/a > 6) { k = n/a - 1; vector<int> dx = czynniki2(k); if(dx.size() && k%2 == 0) wynik--; wynik += dx.size(); } } printf("%d\n",wynik ); 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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | //by Michal Gilski #include <cstdlib> #include <cstdio> #include <vector> #include <deque> using namespace std; int ipow(int base, int exp) { int result = 1; for (;;) { if (exp & 1) result *= base; exp >>= 1; if (!exp) break; base *= base; } return result; } int czynnrekur(vector<pair<int,int> > &v, vector<int> &wyn, int k, int suma, int n) { if(k == v.size()) { if(suma != 1 && suma!=n) wyn.push_back(suma); return 0; } pair<int, int> p = v[k]; for (int i = 0; i <= p.second; ++i) { czynnrekur(v, wyn, k+1, suma * ipow(p.first, i), n); } } vector<pair<int,int> > czynniki_pierw (int a) { int k = 2; int l; vector<pair<int,int> > v; while(a > 1) { if (!(a%k)) { l = 0; while(!(a%k) && a > 1) { a/=k; l++; } if(k > 1)v.push_back(pair<int,int> (k,l)); } else k++; if(k*k > a) { if(a > 1)v.push_back(pair<int,int> (a,1)); break; } } return v; } vector<int> czynniki2(int a) { vector<pair<int,int> > v; v = czynniki_pierw(a); vector<int> w; czynnrekur(v, w, 0, 1, a); return w; } int main(int argc, char const *argv[]) { int n; scanf("%d", &n); vector<int> w; w = czynniki2(n); w.push_back(1); int a,k; int wynik = 0; for (int i = 0; i < w.size(); ++i) { a = w[i]; if (n/a > 6) { k = n/a - 1; vector<int> dx = czynniki2(k); if(dx.size() && k%2 == 0) wynik--; wynik += dx.size(); } } printf("%d\n",wynik ); return 0; } |