阅读869 返回首页    go 阿里云 go 技术社区[云栖]


projecteuler_problem12

problem12

地址:https://projecteuler.net/problem=12
源码:git@code.aliyun.com:qianlizhixing12/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;
}

最后更新:2017-10-02 21:08:01

  上一篇:go  阿里云最便宜的服务器多少钱?199一年!
  下一篇:go  projecteuler_problem11