12 - highly divisible triangular number

The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be:

1, 3, 6, 10, 15, 21, 28, 36, 45, 55, …

Let us list the factors of the first seven triangle numbers:

highly_divisible_triangular_number_1

We can see that 28 is the first triangle number to have over five divisors.

What is the value of the first triangle number to have over five hundred divisors?

cevap: 76576500

link

#include "stdafx.h"

void calculate_triangle_number(int *, int *);
void calculate_divisor_number(int *, int *);

int _tmain(int argc, _TCHAR* argv[]) {

    int triangle_number = 1;
    int divisor_number = 0;
    int i = 2;

    while (1) {

        calculate_triangle_number(&triangle_number, &i);
        calculate_divisor_number(&triangle_number, &divisor_number);
        i++;

        if(divisor_number > 500)
            break;

    }

    printf("sonuc = %d",triangle_number);

    return 0;
}

void calculate_triangle_number(int *triangle_number, int *i){

    *triangle_number += *i;
    *i++;
}

void calculate_divisor_number(int *triangle_number, int *divisor_number){

    int i = 1;
    int counter = 0;

    while(i<=*triangle_number){

        if(*triangle_number % i == 0)
            counter++;

        i++;
    }

    *divisor_number = counter;
}