閱讀672 返回首頁    go 支付寶


projecteuler_problem5

problem5

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

#include <stdio.h>
#include <math.h>
#include "debug.h"
#include "prime.h"

#define NUM 20

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

    debugTime();
    initGlobalPrime();

    if (NUM > globalPrimeNum)
        isPrime(NUM);

    tmpPtrPrimeNode = globalPrimeHead;
    while ((NULL != tmpPtrPrimeNode) && (NUM <= globalPrimeNum)){
        i = 1;
        while (pow(tmpPtrPrimeNode->data, i) < NUM)
            i++;
        lResult *= pow(tmpPtrPrimeNode->data, i - 1);
        tmpPtrPrimeNode = tmpPtrPrimeNode->next;
    }

    printf("Problem5  Answer: %ld\n", lResult);

    freeGlobalPrime();
    debugTime();
    return 0;
}

最後更新:2017-10-02 21:07:46

  上一篇:go  projecteuler_problem6
  下一篇:go  projecteuler_problem4