Skip to content

Instantly share code, notes, and snippets.

@bojieli
Created October 25, 2014 05:20
Show Gist options
  • Save bojieli/640c4a6493db209e4a94 to your computer and use it in GitHub Desktop.
Save bojieli/640c4a6493db209e4a94 to your computer and use it in GitHub Desktop.
Euler Project #12
#include<stdio.h>
static long get_factor_num(long n) {
int factor;
int exp_count = 0;
int ans = 1;
for (factor = 2; n > 1; factor++) {
exp_count = 0;
while (n % factor == 0) {
n /= factor;
++exp_count;
}
ans *= (exp_count + 1);
}
return ans;
}
int main() {
long n;
long num_factor_last = 0, num_factor_now;
for (n = 2; ; n++) {
if (n % 2) {
num_factor_now = get_factor_num(n);
} else {
num_factor_now = get_factor_num(n / 2);
}
if (num_factor_last * num_factor_now > 500) {
break;
}
num_factor_last = num_factor_now;
}
printf("%ld\n", n * (n-1) / 2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment