Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,23 @@
|
|||
public class Narc{
|
||||
public static boolean isNarc(long x){
|
||||
if(x < 0) return false;
|
||||
|
||||
String xStr = Long.toString(x);
|
||||
int m = xStr.length();
|
||||
long sum = 0;
|
||||
|
||||
for(char c : xStr.toCharArray()){
|
||||
sum += Math.pow(Character.digit(c, 10), m);
|
||||
}
|
||||
return sum == x;
|
||||
}
|
||||
|
||||
public static void main(String[] args){
|
||||
for(long x = 0, count = 0; count < 25; x++){
|
||||
if(isNarc(x)){
|
||||
System.out.print(x + " ");
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
import java.util.stream.IntStream;
|
||||
public class NarcissisticNumbers {
|
||||
static int numbersToCalculate = 25;
|
||||
static int numbersCalculated = 0;
|
||||
|
||||
public static void main(String[] args) {
|
||||
IntStream.iterate(0, n -> n + 1).limit(Integer.MAX_VALUE).boxed().forEach(i -> {
|
||||
int length = i.toString().length();
|
||||
int addedDigits = 0;
|
||||
|
||||
for (int count = 0; count < length; count++) {
|
||||
int value = Integer.parseInt(String.valueOf(i.toString().charAt(count)));
|
||||
addedDigits += Math.pow(value, length);
|
||||
}
|
||||
|
||||
if (i == addedDigits) {
|
||||
numbersCalculated++;
|
||||
System.out.print(addedDigits + " ");
|
||||
}
|
||||
|
||||
if (numbersCalculated == numbersToCalculate) {
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue