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
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <vector>
#define MAX_PRI 40000

using namespace std;


void FillPrime(long n);
void FillPrime2(long n);
void ListDivisors(long n);
long CountDivisors(long n);
long CountDivisors2(long n);
long CountKL(long a);

vector<long> prime;
int pri[MAX_PRI];

int main(int argc, char** argv) {
    long n, a, k, l, r;
    long counter = 0;
    cin >> n;
    long maxSqrt=sqrt(n);
    prime.reserve(3500);
    FillPrime2(maxSqrt);
    for(a=1;a<=maxSqrt;a++){
        if(n%a == 0){
            counter += CountKL(n/a - 1);
            if(a*a<n)
                counter += CountKL(a - 1);
        }
    }
    cout << counter;
    return 0;
}

void FillPrime(long n){
    prime.push_back(2);
    for(long candidate=3; candidate<=n; candidate+=2){
        bool isPrime=true;
        for(auto p : prime)
            if(candidate % p == 0){
                isPrime=false;
                break;
            }
        if(isPrime)
            prime.push_back(candidate);
    }
}

void FillPrime2(long n){
   for(int i=0;i<MAX_PRI;i++)
       pri[i]=1;
   pri[0]=pri[1]=0;
   for(int i=2;i<MAX_PRI;i++){
       if(pri[i]==0)
           continue;
       int k=i*2;
       while(k<MAX_PRI){
           pri[k]=0;
           k+=i;
       }
   }
   for(int i=2;i<MAX_PRI;i++)
       if(pri[i]==1)
           prime.push_back(i);
}

long CountDivisors(long n){
    long k = n;
    long output = 1;
    vector<long>::iterator it = prime.begin();
    long sqr = sqrt(n);
    while(k>1 && it != prime.end() && *it <= sqr){
        long val = *it;
        long count = 0;
        while(k % val == 0){
            count++;
            k/= val;
        }
        output *= count+1;
        it++;
    }
    if(k>1)
        output *= 2;
    return output;
}

long CountKL(long a){
    if(a<6)
        return 0;
    long output = CountDivisors(a) - 2;
    if(a%2==0)
        output -= 1;
    return output;
}

/*long CountDivisors2(long n){
    long output = 0;
    for(long i=1;i<=n;i++)
        if(n%i == 0)
            output++;
    return output;
}*/