projecteulerproblem12

37次阅读

共计 430 个字符,预计需要花费 2 分钟才能阅读完成。

problem12

地址:https://projecteuler.net/problem=12。
源码:git@code.aliyun.com:c-program/projecteuler.git。
问题:1 + 2 + 3 + … 的和中第一个有超过 500 个因数。

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

#define NUM 500

int main(int argc, char **argv){
    int i = 0;
    int sum = 0;
    int num = 0;
    int j;

    debugTime();

    while (num <= NUM){
        i++;
        sum = i * (i + 1) / 2;
        num = 0;
        j = 1;
        while (j <= (sum / j)){if (0 == (sum  % j)){if (j == (sum  / j)) num++;
                else num += 2;
            }
            j++;
        }  
    }
    
    printf("Problem12  Answer: %d\n", sum);

    debugTime();
    return 0;
}

正文完
 0