projecteuler_problem5

problem5

地址:https://projecteuler.net/problem=5
源碼:git@code.aliyun.com:c-program/projecteuler.git。
問題:找到能整除1到20最小的數。git

#include <stdio.h>
#include <math.h>
#include "elr_debug.h"
#include "elr_list_int.h"
#include "elr_prime.h"


#define NUM 20

int main(int argc, char **argv){
    pIntNode tmpPrimeNode;
    int i;
    long int lResult = 1;

    elrDebugTime(EDT_BEGIN);
    initGlobalPrime();

    if (NUM > globalPrimeNum)
        isPrime(NUM);

    tmpPrimeNode = globalPrime;
    do{
        if (NUM < tmpPrimeNode->data) break;
        i = 1;
        while (pow(tmpPrimeNode->data, i) < NUM)
            i++;
        lResult *= pow(tmpPrimeNode->data, i - 1);
        tmpPrimeNode = tmpPrimeNode->next;
    }while (globalPrime != tmpPrimeNode);
    
    printf("Problem5  Answer: %ld\n", lResult);

    freeGlobalPrime();
    
    elrDebugTime(EDT_SPEND);
    elrDebugTime(EDT_END);
    return 0;
}
本站公眾號
   歡迎關注本站公眾號,獲取更多信息