Exemplo n.º 1
0
u64 SumOfDivisorsOfBinomialCoefficient(u64 n, u64 k) {
    if (n == 2) {
        return k == 1 ? 3 : 1;
    } else if (n < 2) {
        return 1;
    }

    Vector primes = GetPrimes(n);
    Vector powers;
    for (auto x: primes) {
        powers.push_back(
            PowerOfDivisor(x, n) -
            PowerOfDivisor(x, k) -
            PowerOfDivisor(x, n - k) 
        );
    }

    u64 result = 1;
    for (u64 i = 0; i < primes.size(); ++i) {
        u64 sum_of_powers = 0;
        u64 x = 1;
        for (u64 p = 0; p <= powers[i]; ++p) {
            sum_of_powers = Sum(sum_of_powers, x);
            x = Mul(x, primes[i]);
        }
        result = Mul(result, sum_of_powers);
    }
    return result;
}
Exemplo n.º 2
0
int main (int argc, char *argv[]) 
{
    std::vector<int> primes;
    GetPrimes (MAXIMUM_VALUE, primes);
    
    int leadValue = 0;
    int consecutivePrimeCount = 0;
    
    // Examine all integers up to the maximum value
    // Start at one so we don't try to factor zero
    for (int i = 1; i < MAXIMUM_VALUE; i++)
    {   
        int factorCount = GetPrimeFactors (i, primes);
        
        // Reset the counter if we didn't get the right number of factors
        if (factorCount != TARGET_FACTOR_COUNT)
        {
            consecutivePrimeCount = 0;
            continue;
        }
        
        // If this is the first in a new potential sequence 
        // then keep track of the lead integer value
        if (consecutivePrimeCount == 0)
            leadValue = i;
        
        consecutivePrimeCount++;
        
        // Determine if we have found the target run
        if (consecutivePrimeCount == TARGET_RUN_LENGTH)
            break;
    }
    
    std::cout << "The target integer is: " << leadValue << std::endl;
}
Exemplo n.º 3
0
 void Pack(Ctxt &ctxt, const std::vector<long> &slots, int bits) const {
     auto tmp_primes = GetPrimes(bits);
     assert(slots.size() <= tmp_primes.size());
     auto crt = MDL::CRT(slots, tmp_primes);
     Encrypt(ctxt, crt);
 }
Exemplo n.º 4
0
    void Pack(Ctxt &ctxt, long m, int bits) const {
		auto tmp_primes = GetPrimes(bits);
        std::vector<long> mm(tmp_primes.size(), m);
        auto crt = MDL::CRT(mm, tmp_primes);
        Encrypt(ctxt, crt);
    }