Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- #include <math.h>
- ntotest (int x)
- {
- int i,kq=1;
- if (x>3)
- {
- for (i=2;i<=pow(x,0.5);i++)
- {
- if (x%i==0) kq=0;
- }
- }
- return(kq);
- }
- void main()
- {
- int n=1,i,dem=0,d,dd=0,m,last,check=3,nto[1000],ntodem[1000];
- while (dd!=check)
- {
- n++;
- i=0,dem=0,d=0,m=0,last=0;
- printf("\n\n %d ",n);
- // Tim cac so nguyen to tu 1 den n
- for (i=1;i<=n;i++)
- {
- if (ntotest(i)==1)
- {
- dem++;nto[dem]=i;
- }
- }
- // Gan cac so mu = 0
- for (i=2;i<=dem;i++) ntodem[i]=0;
- // Phan tich ra thanh thua so cac so nguyen to
- m=n;
- for (i=2;i<=dem;i++)
- {
- while (m%nto[i]==0)
- {
- m=m/nto[i];ntodem[i]++;last=i;
- }
- }
- printf("ket qua la: ");
- for (i=2;i<=dem;i++)
- {
- if (ntodem[i]!=0)
- {
- printf("%d^%d", nto[i], ntodem[i]);
- if (i<last) printf ("x");
- d++;
- }
- }
- printf(" --> d=%d",d);
- if (d==check) dd++;
- else dd = 0;
- }
- printf("\n\n**** Ket qua **** \n");
- for (i=check-1; i>=0; i--) printf("%d ",n-i);
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment