JAVA
java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Created by Swapnil More
/*
Odious numbers are non-negative numbers that have an odd number of ones in the binary expansion
# 21 = 10101 = 3
# 50 = 110010 = 3
This code finds how many odious numbers are smaller than 10,000
*/
// Challenge thread is in the comments section
public class Program
{
public static void main(String[] args) {
int n=0,x,a,b=0,i,c=0,j;
int[] arr = new int[500];
for(i=1;i<10000;i++){
x=i;
while(x!=0){
a=x%2;
x=x/2;
arr[b]=a;
b++;
}
for(j=b;j>=0;j--){
if(arr[j]==1){
c++;
}
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run