Exemple #1
0
// Count how many numbers divide evenly into every number from 0 to max_num.
divisible test_to(unsigned long max_num)
{
	unsigned long test_num;
	divisible number = new_divisible(0);
	divisible current_number = new_divisible(0);

	for (test_num = 0; test_num <= max_num; test_num++) {
		set_value(current_number, test_num);
		if (get_num_divisors(current_number) > get_num_divisors(number)) {
			set_value(number, get_value(current_number));
		}
	}

	free_divisible(current_number);
	return number;
}
int main() {
  int last = 500;
  last /= 2;  // halve the value passed since we count up to the square root
              // which will give us half of the divisors

  int num = 0;
  int i = 0;
  int j = 1;
  while (num < last) {
    i = i + j;
    num = get_num_divisors(i);
    j++;
  }
  printf("%d\n", i);
  return(0);
}