Advertisement
IlidanBabyRage

123.c

Sep 23rd, 2015
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.64 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. typedef long long int lli;
  6.  
  7. int main(){
  8.     lli x = 0;
  9.     scanf ("%lld", &x);
  10.     lli tmp = sqrt(x);
  11.     char *mas = (char*) malloc (tmp * sizeof (char));
  12.     lli del = 0;
  13.     for (lli i = 0; i < tmp; i++) mas[i] = 1;
  14.     for (lli i = 2; i*i < tmp; i++){
  15.         if (mas[i]){
  16.             for(lli j = i * i; j <= tmp; j += i)
  17.                 if(mas[j]) {
  18.                     mas[j] = 0;
  19.                 }
  20.         }
  21.     }
  22.     for (lli i = 2; i <= tmp; i++){
  23.         while (mas[i] && x % i == 0){
  24.             x /= i;
  25.             del = i;
  26.         }
  27.     }
  28.     del = del > x ? del : x;
  29.     if (!del) printf("%lld\n",x );
  30.     else printf("%lld\n", del);
  31.     free(mas);
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement