#include <iostream> #include <cmath> using namespace std; long long factorial(long long n) { int result = 1; for(int i = 1; i <= n; i++) { result *= i; } return result; } int getAmountOfFactors(long long n) { int factors = 0; while(n % 2 == 0) { factors++; n /= 2; } long long b = 3; while(n > 1 && b <= sqrt(n)) { if(n % b == 0) { factors++; n /= b; } else { b += 2; } } if(n > 1) { factors++; } return factors; } long long inspect(long long n, long long N) { if(N % n != 0) { return -1; } n = N / n - 1; long long factors = getAmountOfFactors(n); if(factors > 1) { long long f = factorial(factors - 2); long long f2 = f * (factors - 1) * factors; return f2 / 2 / f; } } int main() { long long n; cin >> n; long long max = (long long) sqrt(n); long long all = 0; for(long long a = 1; a <= max; a++) { long long r = inspect(a, n); if(r != -1) { all += r; } } cout << all; 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 | #include <iostream> #include <cmath> using namespace std; long long factorial(long long n) { int result = 1; for(int i = 1; i <= n; i++) { result *= i; } return result; } int getAmountOfFactors(long long n) { int factors = 0; while(n % 2 == 0) { factors++; n /= 2; } long long b = 3; while(n > 1 && b <= sqrt(n)) { if(n % b == 0) { factors++; n /= b; } else { b += 2; } } if(n > 1) { factors++; } return factors; } long long inspect(long long n, long long N) { if(N % n != 0) { return -1; } n = N / n - 1; long long factors = getAmountOfFactors(n); if(factors > 1) { long long f = factorial(factors - 2); long long f2 = f * (factors - 1) * factors; return f2 / 2 / f; } } int main() { long long n; cin >> n; long long max = (long long) sqrt(n); long long all = 0; for(long long a = 1; a <= max; a++) { long long r = inspect(a, n); if(r != -1) { all += r; } } cout << all; return 0; } |