This is a companion discussion topic for the original entry at https://toph.co/p/tidy-bits
This is a companion discussion topic for the original entry at https://toph.co/p/tidy-bits
import java.util.Scanner;
public class TidyBits {
static int m(int A){
int b=0,m;
while(A!=0){
m=A%2;
A=A/2;
if(m!=0){
b++;
}
}
return b;
}
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
int A;
A=in.nextInt();
int b=m(A);
long d=0;
int c=0;
for (int i = 2; i <=A; i++) {
for (int j = 2; j <=i; j++) {
if(i%j==0){
c++;
}
}
if(c==1){
int k=i;
while(k!=0){
int m1=k%2;
k=k/2;
if(m1!=0){
d++;
}
}
if(d==b){
System.out.print(i+"");
System.exit(0);
}
d=0;
}
c=0;
}
i gat WA in case 3
Worked FIne in Python…
usr = int(input())
emp = list(bin(usr))
final = []
emp.remove('b')
for i in range(len(emp)):
if emp[i] == '0':
i += 1
else:
final.append(int(emp[i]))
digit = 0
for low in range(len(final)):
digit += (final[low]*(2**low))
print(digit)