Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
34
Task/Super-d-numbers/Java/super-d-numbers.java
Normal file
34
Task/Super-d-numbers/Java/super-d-numbers.java
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import java.math.BigInteger;
|
||||
|
||||
public class SuperDNumbers {
|
||||
|
||||
public static void main(String[] args) {
|
||||
for ( int i = 2 ; i <= 9 ; i++ ) {
|
||||
superD(i, 10);
|
||||
}
|
||||
}
|
||||
|
||||
private static final void superD(int d, int max) {
|
||||
long start = System.currentTimeMillis();
|
||||
String test = "";
|
||||
for ( int i = 0 ; i < d ; i++ ) {
|
||||
test += (""+d);
|
||||
}
|
||||
|
||||
int n = 0;
|
||||
int i = 0;
|
||||
System.out.printf("First %d super-%d numbers: %n", max, d);
|
||||
while ( n < max ) {
|
||||
i++;
|
||||
BigInteger val = BigInteger.valueOf(d).multiply(BigInteger.valueOf(i).pow(d));
|
||||
if ( val.toString().contains(test) ) {
|
||||
n++;
|
||||
System.out.printf("%d ", i);
|
||||
}
|
||||
}
|
||||
long end = System.currentTimeMillis();
|
||||
System.out.printf("%nRun time %d ms%n%n", end-start);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue