diff options
Diffstat (limited to 'others/mHoang20150916/pfactor.c')
-rw-r--r-- | others/mHoang20150916/pfactor.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/others/mHoang20150916/pfactor.c b/others/mHoang20150916/pfactor.c new file mode 100644 index 0000000..fee50b5 --- /dev/null +++ b/others/mHoang20150916/pfactor.c @@ -0,0 +1,21 @@ +#include <stdio.h> +#include <math.h> + +int main() +{ + long long n, sqrtn; + long i, tmp; + + scanf("%lld", &n); + sqrtn = sqrt(n); + + for (i = 2; i <= sqrtn && n > 1; i++) + while (n % i == 0) { + n /= i; + tmp = i; + } + + printf("%lld\n", (n == 1) ? tmp : n); + + return 0; +} |