Bleak Numbers In Mathematics each number has one special number, which it supports, chosen as follows. It counts the number of ones in its own binary representation, and adds this count to itself to obtain the value of the number it supports. That is, if j(m) means the number of ones in the binary representation of m, then m supports m+j(m). For example, the number eight (1000 in binary) supports nine, whereas nine supports eleven. However, in this way not all the numbers get supported; some are left without support, and we call these numbers bleak. For example since one supports two, two supports three and three supports five, there is no number less than four, which would support four, so four is bleak. Your task is for a given number recognize if it is bleak or supported by some number. How to solve this question asked 26 Oct '14, 22:00

Brother, you'll get your answer here : http://www.careercup.com/question?id=5661070769258496 answered 28 Oct '14, 20:17

Suppose you have a number 'm' and it is supported by another number say 'n'. We know n < m. Therefore, the maximum number of set bits in the binary representation of 'n' will be log2(m). (Logarithm of 'm' w.r.t. base 2). For each i, (1 <= i <= log2(m)), check if number of set bits in (mi) is equal to 'i'. If this is true for any i, then the number m is not bleak, as it will be supported by (mi), otherwise it is bleak. Time complexity: O(k^2), where k is the size of input, that is, log2(m). So, now, we have a polynomial time algorithm to determine if a number is bleak. Sample code in C++. You can easily extend this for "big" numbers, if needed.
answered 28 Oct '14, 19:42

most optimized and well explained solution http://www.waytocrack.com/blog/howtocheckifanumberisbleakorsupportednumber/ answered 23 Jul '17, 12:18

// this is the solution in vs cpp include "stdafx.h"include<iostream>include<conio.h>include <bitset>using namespace std; int main() { int i,j; int size; cin>>size; int *arr=new int[size]; for(i=0;i<size;i++) {="" cin="">>arr[i]; } for(i=0;i<size;i++) {="" bitset<32="">a=arr[i]; bitset<32>b=1; int b_deci=b.to_ulong(); int flag=0; for(j=0;b_deci<=arr[i];j++) { if(b_deci==arr[i]) { flag=1; cout<<"SUPPORTED"; break; } else { b_deci+=b.count(); b=b_deci; } } if(flag==0) { cout<<"BLEAK"; } } _getch(); } answered 07 Nov '14, 01:19

Full Solution in Java public class BleakNumber{
} answered 19 Sep '15, 23:35

for c include<stdio.h>include<math.h>include<stdlib.h>define sz 10int bin( ); int check(int,int ); int main() { int i; bin(); return 0; } int bin( ) { int gn,i;
} int check(int gn,int chk) { int i=0,j=0,gn1,gn2; int bn[sz]; gn1=gn; gn2=gn;
} answered 18 Feb '16, 02:50

what are the constraints ??
If you have taken this question from another site, please mention the source.
How does it make a difference where the question is taken from!! Constraints you can take say n<10^6 ,though i want the general solution!