p12
This commit is contained in:
parent
428e392868
commit
280f6917d8
1 changed files with 40 additions and 0 deletions
40
p12.c
Normal file
40
p12.c
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
|
||||||
|
/*
|
||||||
|
* http://projecteuler.net
|
||||||
|
*
|
||||||
|
* Projecteuler - Problem 12
|
||||||
|
* ------------------------
|
||||||
|
* 2010-06-18 Henrik Hautakoski
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "lib/prime.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int ndiv(int n) {
|
||||||
|
|
||||||
|
int i, exp, ndiv = 1;
|
||||||
|
|
||||||
|
for(i=2; i <= n; i++) {
|
||||||
|
|
||||||
|
if (!is_prime(i))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
for(exp = 0; n % i == 0; n /= i, exp++);
|
||||||
|
|
||||||
|
if (exp > 0)
|
||||||
|
ndiv *= exp+1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ndiv;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
|
||||||
|
int i, num = 1;
|
||||||
|
|
||||||
|
for(i=2; ndiv(num) <= 500; num += i++);
|
||||||
|
|
||||||
|
printf("%i\n", num);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue