thieumao

Ba số liên tiếp đầu tiên đc tạo bởi tích các thừa số nguyên

Oct 11th, 2013
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.36 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <math.h>
  4.  
  5. ntotest (int x)
  6. {
  7.     int i,kq=1;
  8.     if (x>3)
  9.     {
  10.         for (i=2;i<=pow(x,0.5);i++)
  11.         {
  12.             if (x%i==0) kq=0;
  13.         }
  14.     }
  15.     return(kq);
  16. }
  17.  
  18. void main()
  19. {
  20.     int n=1,i,dem=0,d,dd=0,m,last,check=3,nto[1000],ntodem[1000];
  21.     while (dd!=check)
  22.     {
  23.         n++;
  24.         i=0,dem=0,d=0,m=0,last=0;
  25.         printf("\n\n %d ",n);
  26.         // Tim cac so nguyen to tu 1 den n
  27.         for (i=1;i<=n;i++)
  28.         {
  29.             if (ntotest(i)==1)
  30.             {
  31.                 dem++;nto[dem]=i;
  32.             }
  33.         }
  34.         // Gan cac so mu = 0
  35.         for (i=2;i<=dem;i++) ntodem[i]=0;
  36.         // Phan tich ra thanh thua so cac so nguyen to
  37.         m=n;
  38.         for (i=2;i<=dem;i++)
  39.         {
  40.             while (m%nto[i]==0)
  41.             {
  42.                 m=m/nto[i];ntodem[i]++;last=i;
  43.             }
  44.         }
  45.         printf("ket qua la: ");
  46.         for (i=2;i<=dem;i++)
  47.         {
  48.             if (ntodem[i]!=0)
  49.             {
  50.                 printf("%d^%d", nto[i], ntodem[i]);
  51.                 if (i<last) printf ("x");
  52.                 d++;
  53.             }
  54.         }
  55.         printf(" --> d=%d",d);
  56.         if (d==check) dd++;
  57.         else dd = 0;
  58.     }
  59.     printf("\n\n**** Ket qua **** \n");
  60.     for (i=check-1; i>=0; i--) printf("%d ",n-i);
  61.     getch();
  62. }
Advertisement
Add Comment
Please, Sign In to add comment