Source code bài 1

#include <stdio.h>
#include <math.h>
int ngto(int x);
void main()
{
int x,i,d,a[100],t[100],k[100],n1,n2,vt,n;
printf(“nhap vao so a: “); scanf(“%d”,&x);
d=0;
for (i=1;i<=99;i++) k[i]=0;
for (i=2;i<=x;i++)
if (ngto(i) &&(x%i==0))
{
d++; a[d]=i;
while ((x%i==0)&&(x>=0))
{
k[d]++;
x=x/i;
}
}
n=1; vt=1;
for (i=1;i<=d;i++)
{
if (k[i]>k[vt]) vt=i;
n=n*a[i];
t[i]=1;
}
if (k[vt]>n)
{
n1=n*(k[vt]/n+1);
n2=n;
do
{
n2=n2*a[vt]; t[vt]++;
i=1;
while ((t[i]*n2>k[i])&&(i<=d)) i++;
if (i<=d) vt=i;
} while (t[vt]*n2<k[vt]);
if (n1<n2) n=n1; else n=n2;
}
printf(“n= %d”,n);
printf(“\n”);
}
int ngto(int x)
{
int i=2,j;
j=(int) sqrt((double) x);
while ((i<=j)&&(x%i!=0)) i++;
if (i>j) return 1;
else return 0;
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s