Advertisement
cd62131

factorize

Mar 28th, 2014
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.71 KB | None | 0 0
  1. #include <stdio.h>
  2. int main(void) {
  3.   int i, j, x, f, fact = 0, max = 0;
  4.   for (i = 2; i < 10000; i++) {
  5.     x = i;
  6.     f = 0;
  7.     while (x >= 4 && x % 2 == 0) {
  8.       f++;
  9.       x /= 2;
  10.     }
  11.     j = 3;
  12.     while (j * j <= x) {
  13.       if (x % j != 0) j += 2;
  14.       else {
  15.         f++;
  16.         x /= j;
  17.       }
  18.     }
  19.     if (x != 1) f++;
  20.     if (fact < f) {
  21.       fact = f;
  22.       max = i;
  23.     }
  24.   }
  25.   printf("%d = ", max);
  26.   while (max >= 4 && max % 2 == 0) {
  27.     printf("2 * ");
  28.     max /= 2;
  29.   }
  30.   j = 3;
  31.   while (j * j <= max) {
  32.     if (max % j != 0) j += 2;
  33.     else {
  34.       printf("%d * ", j);
  35.       max /= j;
  36.     }
  37.   }
  38.   printf("%d\n", max);
  39.   printf("elem: %d\n", fact);
  40.   return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement