Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
10
Task/Munchausen-numbers/Java/munchausen-numbers-1.java
Normal file
10
Task/Munchausen-numbers/Java/munchausen-numbers-1.java
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
for(int i = 0 ; i <= 5000 ; i++ ){
|
||||
int val = String.valueOf(i).chars().map(x -> (int) Math.pow( x-48 ,x-48)).sum();
|
||||
if( i == val){
|
||||
System.out.println( i + " (munchausen)");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
29
Task/Munchausen-numbers/Java/munchausen-numbers-2.java
Normal file
29
Task/Munchausen-numbers/Java/munchausen-numbers-2.java
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
public class Munchhausen {
|
||||
|
||||
static final long[] cache = new long[10];
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Allowing 0 ^ 0 to be 0
|
||||
for (int i = 1; i < 10; i++) {
|
||||
cache[i] = (long) Math.pow(i, i);
|
||||
}
|
||||
for (long i = 0L; i <= 500_000_000L; i++) {
|
||||
if (isMunchhausen(i)) {
|
||||
System.out.println(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isMunchhausen(long n) {
|
||||
long sum = 0, nn = n;
|
||||
do {
|
||||
sum += cache[(int)(nn % 10)];
|
||||
if (sum > n) {
|
||||
return false;
|
||||
}
|
||||
nn /= 10;
|
||||
} while (nn > 0);
|
||||
|
||||
return sum == n;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue