#include <cstdio> #include <vector> #define FOR(i,a,b) for(int i=(a);i<(b);++i) //#define DEBUG(x...) printf(x) #define DEBUG(x...) using namespace std; typedef unsigned long long LL; const int PMAX = 31625; bool E[PMAX]; vector<int> P; void prepare_primes() { E[1] = 0; P.reserve(3405); FOR(i,2,PMAX) { if(not E[i]) { P.push_back(i); //DEBUG("%d ", i); } int j = 2 * i; while(j < PMAX) { E[j] = 1; j += i; } } DEBUG("\n%d\n", P.size()); } LL d(int k) { LL res = 1; int i = 0, s = P.size(); while(1 < k and i < s) { int fct = 1; while(k % P[i] == 0) { DEBUG("%d ", P[i]); k /= P[i]; ++fct; } res *= fct; ++i; } if(1 < k) res *= 2; DEBUG("\n%lld\n", res); return res; } LL d_spec(int k) { if(k < 3) return 0; return d(k) - 2 - int(k % 2 == 0); } int main() { int n; scanf("%d", &n); if(n < 7) { printf("0\n"); return 0; } prepare_primes(); LL res = 0; int k = 1; while(k * k <= n) { if(n % k == 0) { DEBUG("-- %d %d\n", k, n / k); res += d_spec(k - 1); res += d_spec(n / k - 1); } ++k; } printf("%lld\n", res); 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 | #include <cstdio> #include <vector> #define FOR(i,a,b) for(int i=(a);i<(b);++i) //#define DEBUG(x...) printf(x) #define DEBUG(x...) using namespace std; typedef unsigned long long LL; const int PMAX = 31625; bool E[PMAX]; vector<int> P; void prepare_primes() { E[1] = 0; P.reserve(3405); FOR(i,2,PMAX) { if(not E[i]) { P.push_back(i); //DEBUG("%d ", i); } int j = 2 * i; while(j < PMAX) { E[j] = 1; j += i; } } DEBUG("\n%d\n", P.size()); } LL d(int k) { LL res = 1; int i = 0, s = P.size(); while(1 < k and i < s) { int fct = 1; while(k % P[i] == 0) { DEBUG("%d ", P[i]); k /= P[i]; ++fct; } res *= fct; ++i; } if(1 < k) res *= 2; DEBUG("\n%lld\n", res); return res; } LL d_spec(int k) { if(k < 3) return 0; return d(k) - 2 - int(k % 2 == 0); } int main() { int n; scanf("%d", &n); if(n < 7) { printf("0\n"); return 0; } prepare_primes(); LL res = 0; int k = 1; while(k * k <= n) { if(n % k == 0) { DEBUG("-- %d %d\n", k, n / k); res += d_spec(k - 1); res += d_spec(n / k - 1); } ++k; } printf("%lld\n", res); return 0; } |