Algorithms_in_C 1.0.0
Set of algorithms implemented in C.
|
Problem 12 solution More...
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
Functions | |
long | count_divisors (long long n) |
Get number of divisors of a given number. | |
int | main (int argc, char **argv) |
Main function. | |
Problem 12 solution
long count_divisors | ( | long long | n | ) |
Get number of divisors of a given number.
If \(x = a \times b\), then both \(a\) and \(b\) are divisors of \(x\). Since multiplication is commutative, we only need to search till a maximum of \(a=b = a^2\) i.e., till \(\sqrt{x}\). At every integer till then, there are eaxctly 2 divisors and at \(a=b\), there is only one divisor.
int main | ( | int | argc, |
char ** | argv | ||
) |
Main function.