/**
* Author:- nikhil.lohia
*/
class Ideone {
public Ideone() {
}
public static void main
(String[] args
) { Ideone method2 = new Ideone();
// Code obtained from http://w...content-available-to-author-only...s.com
// Feel free to copy but please acknowledge wherever possible
method2.findPrimes(25);
}
private void findPrimes(int limit) {
// Special handling for 2
if (limit > 2)
for (int i = 2; i < limit; i++) {
boolean isPrime = true;
// Utilizing our previous optimizations
if (i % 2 == 0) {
isPrime = false;
}
// Get the square root
int s
= (int) Math.
sqrt(i
);
// We need to loop only until the square root of that number
for (int j = 3; j <= s; j += 2) {
if (i % j == 0) {
isPrime = false;
}
}
if (isPrime)
}
}
}
LyoqCiAqIEF1dGhvcjotIG5pa2hpbC5sb2hpYQogKi8KY2xhc3MgSWRlb25lIHsKCiAgICBwdWJsaWMgSWRlb25lKCkgewogICAgfQoKICAgIHB1YmxpYyBzdGF0aWMgdm9pZCBtYWluKFN0cmluZ1tdIGFyZ3MpIHsKICAgICAgICBJZGVvbmUgbWV0aG9kMiA9IG5ldyBJZGVvbmUoKTsKICAgICAgICAvLyBDb2RlIG9idGFpbmVkIGZyb20gaHR0cDovL3cuLi5jb250ZW50LWF2YWlsYWJsZS10by1hdXRob3Itb25seS4uLnMuY29tCiAgICAgICAgLy8gRmVlbCBmcmVlIHRvIGNvcHkgYnV0IHBsZWFzZSBhY2tub3dsZWRnZSB3aGVyZXZlciBwb3NzaWJsZQogICAgICAgIG1ldGhvZDIuZmluZFByaW1lcygyNSk7CiAgICB9CgogICAgcHJpdmF0ZSB2b2lkIGZpbmRQcmltZXMoaW50IGxpbWl0KSB7CgogICAgICAgIC8vIFNwZWNpYWwgaGFuZGxpbmcgZm9yIDIKICAgICAgICBpZiAobGltaXQgPiAyKQogICAgICAgICAgICBTeXN0ZW0ub3V0LnByaW50KCIyLCIpOwoKICAgICAgICBmb3IgKGludCBpID0gMjsgaSA8IGxpbWl0OyBpKyspIHsKCiAgICAgICAgICAgIGJvb2xlYW4gaXNQcmltZSA9IHRydWU7CgogICAgICAgICAgICAvLyBVdGlsaXppbmcgb3VyIHByZXZpb3VzIG9wdGltaXphdGlvbnMKICAgICAgICAgICAgaWYgKGkgJSAyID09IDApIHsKICAgICAgICAgICAgICAgIGlzUHJpbWUgPSBmYWxzZTsKICAgICAgICAgICAgfQoKICAgICAgICAgICAgLy8gR2V0IHRoZSBzcXVhcmUgcm9vdAogICAgICAgICAgICBpbnQgcyA9IChpbnQpIE1hdGguc3FydChpKTsKCiAgICAgICAgICAgIC8vIFdlIG5lZWQgdG8gbG9vcCBvbmx5IHVudGlsIHRoZSBzcXVhcmUgcm9vdCBvZiB0aGF0IG51bWJlcgogICAgICAgICAgICBmb3IgKGludCBqID0gMzsgaiA8PSBzOyBqICs9IDIpIHsKICAgICAgICAgICAgICAgIGlmIChpICUgaiA9PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgaXNQcmltZSA9IGZhbHNlOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CgogICAgICAgICAgICBpZiAoaXNQcmltZSkKICAgICAgICAgICAgICAgIFN5c3RlbS5vdXQucHJpbnQoaSArICIsIik7CiAgICAgICAgfQoKICAgIH0KfQ==