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,i,dem=0,m,last,nto[1000],ntodem[1000];
- printf("nhap n:");scanf("%d", &n);
- for (i=1;i<=n;i++)
- {
- if (ntotest(i)==1)
- {
- dem++;nto[dem]=i;
- }
- }
- m=n;
- for (i=2;i<=dem;i++) ntodem[i]=0;
- 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");
- }
- }
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment