Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Решето Эратосфена
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
//'main' method must be in a class 'Rextester'. //Compiler version 1.8.0_111 import java.util.*; import java.lang.*; class Rextester { public static void main(String args[]) { int maxN = 100_000; int[] primes = new int[10_000]; int primesCount = 0; for (int i = 2; i <= maxN; i++) { int maxDiv = (int) Math.sqrt(i); boolean isPrime = true; for (int divIndex = 0; primes[divIndex] <= maxDiv && divIndex < primesCount; divIndex++) if (i % primes[divIndex] == 0) { isPrime = false; break; } if (isPrime) primes[primesCount++] = i; } System.out.println(primesCount + ": " + primes[primesCount - 1]); } }
[
+
]
Show input
Compilation time: 0.63 sec, absolute running time: 0.23 sec, cpu time: 0.27 sec, memory peak: 19 Mb, absolute service time: 0,87 sec
edit mode
|
history
|
discussion
9592: 99991