Professional Documents
Culture Documents
Java
Java
t=t*x;
// Tnh gi tr t
m=m*i;
// Tnh gi tr mu
Thut ton
- So snh hai s a v b . Tm hiu hai s cho ti khi chng bng nhau
Code
Public static int UCLN(int a,int b)
While(a!=b)
If(a>b) a=a-b;
else b=b-a; }
return a
}
BCNN l a*b/UCLN(a,b)
int s=0,x;
while(a!=0)
{
y=a%10;
// Tch ly s cui
a=a/10;
s=s+y;
}
}
{
for(i=2;i<=math.sqrt(a);i++)
if(a%i==0) return flase;
return true;
}
}
(2). In ra cc s nguyn t nh hn n.
Int i;
for(i=2;i<=n;i++)
if(nto(i))
system.out.print( + i);
(3.1). In ra n s nguyn t
- Cn c mt bin m kim tra xem ng l bng n cha
int dem=0,i=2;
while(dem!=n)
{
if(nto(i))
{
system.out.print(i)
dem++;
}
else
i++;
}
(3.2) Cch 2
- Do ta bit vng lp nn s dng for vi iu kin dng l dem<=n
Int dem=0,i;
for(i=2;dem<=n;i++)
{
if(nto(i))
system.out.print( + i)
dem++;
}
}