Код: Выделить всё
1
2
3
5
7
11
13
........................ etc äî 10000
Модератор: Злобный
Код: Выделить всё
1
2
3
5
7
11
13
........................ etc äî 10000
Код: Выделить всё
public class blah {
public static void main(String[] args) {
for(int i = 3; i < 100; i+=2)
{
int count = 0;
for(int x = 3; x <=i; x+= 2)
{
if(i%x==0)
{
count++;
}
}
if(count==1)
{
System.out.println(i);
}
}
}
}
Код: Выделить всё
public class Primes
{public static void main(String[] args)
{for(int i=1;i<10000;i+=2)
{int p,m=Math.sqrt(i);
for(int x=3;x<=m;x+=2)
if(!(p=i%x)) break;
if(p) System.out.println(i);
}
}
}
Код: Выделить всё
int p,m=Math.sqrt(i);
possible loss of precision
Код: Выделить всё
public class Primes {
public static void main(String[] args) {
long t1 = System.currentTimeMillis();
int m = 10000;
for (int i=2; i<m; ++i) {
if (isprime(i)) {
System.out.println(i);
}
}
long t2=System.currentTimeMillis();
long t=t2-t1;
System.out.println("vremya = " + t);
}
public static boolean isprime(int chislo){
long m = Math.round(Math.sqrt(chislo)) + 1;
for (int i=2; i<m; ++i) {
if (chislo%i == 0) {
return false;
}
}
return true;
}
}
Код: Выделить всё
public class LowerBound
{public static void main(String[] args)
{long t1=System.currentTimeMillis();
int m=1000,n=2500;
for(int i=0;i<n;++i)
System.out.println(m);
long t2=System.currentTimeMillis();
long t=t2-t1;
System.out.println("vremya = " + t);
}
}
Код: Выделить всё
{int p,m=Math.sqrt(i);
Код: Выделить всё
if(!(p=i%x)) break;
Код: Выделить всё
if(p)