Advertisement
Ladies_Man

1_7 Eratosthenes наиб простой делитель (Эратосфен)

Dec 30th, 2013
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.33 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main(void)
  4. {
  5.   int n,i,j,max=0,k;
  6.   scanf("%d",&n);
  7.   n=abs(n);
  8.   k=(int)(sqrt(n))+2;
  9.   int A[k];
  10.   for (i=2;i<=k;i++) {
  11.     A[i]=1;
  12.   }
  13.   for (i=2;i<=(int)(sqrt(k))+1;i++) {
  14.     if (A[i]==1)
  15.       for (j=i*i;j<=k;j+=i) {
  16.         A[j]=0;
  17.       }
  18.   }
  19.   for (i=2;i<=k;i++) {
  20.     if (A[i]==1) {
  21.       while (!(n%i)) {
  22.         max=i;
  23.         n=n/i;
  24.       }
  25.     }
  26.   }
  27.   if (n>1)
  28.     max=n;
  29.   printf("%d",max);
  30.   return 0;
  31. }
  32.  
  33.  
  34.  
  35.  
  36. #include <stdio.h>
  37. #include <math.h>
  38.  
  39. int main()
  40. {
  41.         int x;
  42.         scanf ("%d", &x);
  43.         int t=ceil(sqrt(abs(x))+1);
  44.         int array[t];
  45.         int i, j;
  46.         for (i=0; i<=t; i++) {
  47.                 array[i]=i;
  48.         }
  49.         for (i=2; i<=t; i=i++) {
  50.                 if(array[i]!=0) {
  51.                         for (j=i*2; j<=t; j=j+i) {
  52.                                 array[j]=0;
  53.                         }
  54.                 }
  55.         }
  56.         array[1]=0;
  57.         for (i=2; i<t; i++) {
  58.                 if (((array[i])!=0) && (x%array[i]==0) && (x!=array[i]))
  59.                         x=x/array[i];
  60.                 if ((x % i == 0) && (x != array[i])) {
  61.                         while (x % i == 0)
  62.                         x = x/array[i];
  63.                 }
  64.         }
  65.         x=abs(x);
  66.         printf ("%d", x);
  67.         return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement