This is basically the simplest way, there should be no one, hehe ~
According to the definition of prime numbers: only 1 and himself are divisible. 1 is not prime.
Write down the following code and run it correctly.
Remove the annotation and find out the number of all primes within 1000.
Class FindAll
{
//static int sum=0;
static void find (int i)
{
int t=0;
for (int k=1;k<=1000;k++)
{
if (i%k!=0)
t++;
if (t==998)
System.out.println (i);
Sum+=i
}
}
public static void Main (string[] args)
{for
(int i=0;i<=1000;i++)
{
if (i==1)
continue;
Find (i);
}
SYSTEM.OUT.PRINTLN (sum);
}
The following code is the code that asks for a composite, and the logic is: if a number can be rounded by at least 3 digits, then he is a composite.
Also, remove the annotation to find the sum of all composite numbers within 1000.
Class FindAll
{
//static int sum=0;
static void find (int i)
{
int t=0;
for (int k=1;k<=1000;k++)
{
if (i%k==0)
t++;
if (t==3)
{
System.out.println (i);
sum+=i;
break;
}
}} public static void Main (string[] args)
{for
(int i=0;i<=1000;i++)
{find
(i);
}
SYSTEM.OUT.PRINTLN (sum);
}