BigInteger prime = BigInteger.valueOf(0);
for (int i = 0; i < n; i++) {
prime = prime.nextProbablePrime();
}
System.out.println(prime.intValue());
Sunday, June 28, 2015
Probable Prime using Java Big Integer
Most Efficient Code for Nth Prime
public static int nthprime(int n) {
if (n == 1) return 2;
if (n == 2) return 3;
int limit, root, count = 1;
limit = (int)(n * (Math.log(n) + Math.log(Math.log(n)))) + 3;
root = (int) Math.sqrt(limit) + 1;
limit = (limit - 1) / 2;
root = root / 2 - 1;
boolean[] sieve = new boolean[limit];
for (int i = 0; i < root; ++i) {
if (!sieve[i]) {
++count;
for (int j = 2 * i * (i + 3) + 3, p = 2 * i + 3; j < limit; j += p) {
sieve[j] = true;
}
}
}
int p;
for (p = root; count < n; ++p) {
if (!sieve[p]) {
++count;
}
}
return 2 * p + 1;
}
if (n == 1) return 2;
if (n == 2) return 3;
int limit, root, count = 1;
limit = (int)(n * (Math.log(n) + Math.log(Math.log(n)))) + 3;
root = (int) Math.sqrt(limit) + 1;
limit = (limit - 1) / 2;
root = root / 2 - 1;
boolean[] sieve = new boolean[limit];
for (int i = 0; i < root; ++i) {
if (!sieve[i]) {
++count;
for (int j = 2 * i * (i + 3) + 3, p = 2 * i + 3; j < limit; j += p) {
sieve[j] = true;
}
}
}
int p;
for (p = root; count < n; ++p) {
if (!sieve[p]) {
++count;
}
}
return 2 * p + 1;
}
Sunday, June 21, 2015
CSS Element Full Rotation
/* rotation animation */ @-webkit-keyframes rotate { from { -webkit-transform:rotate(0deg); } to { -webkit-transform:rotate(360deg); } } @-moz-keyframes rotate { from { -moz-transform:rotate(0deg); } to { -moz-transform:rotate(360deg); } } @-ms-keyframes rotate { from { -ms-transform:rotate(0deg); } to { -ms-transform:rotate(360deg); } } @-o-keyframes rotate { from { -o-transform:rotate(0deg); } to { -o-transform:rotate(360deg); } } .rotating { -webkit-transform-origin: 50% 50%; -webkit-animation-name: rotate; -webkit-animation-duration: 1s; -webkit-animation-iteration-count: infinite; -webkit-animation-timing-function: linear; -moz-transform-origin: 50% 50%; -moz-animation-name: rotate; -moz-animation-duration: 1s; -moz-animation-iteration-count: infinite; -moz-animation-timing-function: linear; -ms-transform-origin: 50% 50%; -ms-animation-name: rotate; -ms-animation-duration: 1s; -ms-animation-iteration-count: infinite; -ms-animation-timing-function: linear; -o-transform-origin: 50% 50%; -o-animation-name: rotate; -o-animation-duration: 1s; -o-animation-iteration-count: infinite; -o-animation-timing-function: linear; }
Clean Up Email
[from:noreply* OR from:do-not-reply* OR from:donotreply* OR from:notification*]
[from:news* OR from:digest* OR from:auto* OR from:reports* OR from:*mailer*]
[from:news* OR from:digest* OR from:auto* OR from:reports* OR from:*mailer*]
Friday, June 19, 2015
io to nio
File folder=new Folder("D:\\");
File[] files = folder.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.toLowerCase().endsWith("" + FILE_EXT + "");
}
});
Path dir=Paths.get("D:\\");
DirectoryStream<Path> stream = Files.newDirectoryStream(dir, "*.{" + FILE_EXT + "}");
File[] files = folder.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.toLowerCase().endsWith("" + FILE_EXT + "");
}
});
Path dir=Paths.get("D:\\");
DirectoryStream<Path> stream = Files.newDirectoryStream(dir, "*.{" + FILE_EXT + "}");
Friday, June 12, 2015
Quick System.out.println()
static<T> void z(T arg) { System.out.println(arg); }
use z(object)
buzz around! dump text, write to console, overflow the terminal, debug code
use z(object)
buzz around! dump text, write to console, overflow the terminal, debug code
Subscribe to:
Posts (Atom)
Going one step further with Kotlin & gRPC
Recently, I tried using Quarkus with Kotlin for grpc. I have worked with grpc for communication between microservices in Java & Golang. ...
-
As you might have guessed, I got very busy between March 2021 & March 2022. In fact I have been very busy at work & play between Ma...
-
The JDBC type BIGINT represents a 64-bit signed integer value between -9223372036854775808 and 9223372036854775807. The corresponding SQ...