Update all new Tasks
This commit is contained in:
parent
00a190b0a6
commit
91df62d461
5697 changed files with 93386 additions and 804 deletions
29
Task/Pernicious-numbers/Java/pernicious-numbers.java
Normal file
29
Task/Pernicious-numbers/Java/pernicious-numbers.java
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
public class Pernicious{
|
||||
//very simple isPrime since x will be <= Long.SIZE
|
||||
public static boolean isPrime(int x){
|
||||
if(x < 2) return false;
|
||||
for(int i = 2; i < x; i++){
|
||||
if(x % i == 0) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static int popCount(long x){
|
||||
return Long.bitCount(x);
|
||||
}
|
||||
|
||||
public static void main(String[] args){
|
||||
for(long i = 1, n = 0; n < 25; i++){
|
||||
if(isPrime(popCount(i))){
|
||||
System.out.print(i + " ");
|
||||
n++;
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println();
|
||||
|
||||
for(long i = 888888877; i <= 888888888; i++){
|
||||
if(isPrime(popCount(i))) System.out.print(i + " ");
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue