Program:-
For a number X, let its "Coolness" be defined as the number of "101"s occurring in its binary representation. For example, the number 21 has Coolness 2, since its binary representation is 101012, and the string "101" occurs twice in this representation.
A number is defined as Very Cool if its Coolness is greater than or equal to K. Please, output the number of Very Cool integers between 1 and R.
Input:
The first line contains an integer T, the number of test cases.
The next T lines contains two space-separated integers, R and K.
Output:
Output T lines, the answer for each test case.
Constraints:
1<=T<=100
1<=R<=105
1<=K<=100
Time Limit:5.0 sec(s) for each input file.
Memory Limit:256 MB
Source Limit:
Solution:-
#include<stdio.h>
int very_cool(int n,int k) // funtion definition
{
long long int a[1000000],i=0,j;
int sum=0;
while(n>0)
{
a[i]=n%2;
n=n/2;
i++;
}
for( j=i-1;j>=2;j--)
{
if(a[j]==1&&a[j-1]==0&&a[j-2]==1)
sum++;
}
if(sum>=k)
return 1;
else
return 0;
}
void main()
{
int t,r,k,s,total_no=0;
scanf("%d",&t);
for(int i=0;i<t;i++)
{
scanf("%d%d",&r,&k);
for(int j=5;j<=r;j++)
{
s=very_cool(j,k); // function calling
total_no=total_no+s;
}
printf("%d\n",total_no);
total_no=0;
}
}
Recommended post:-
Hackerearth Problems:-
- Very Cool numbers | Hacker earth solution
- Birthday party | Hacker earth solution
- Most frequent | hacker earth problem solution
- program to find symetric difference of two sets
- cost of balloons | Hacker earth problem solution
- Chacha o chacha | hacker earth problem solution
- jadu and dna | hacker earth solution
- Bricks game | hacker earth problem
- Anti-Palindrome strings | hacker earth solution
- connected components in the graph | hacker earth data structure
- odd one out || hacker earth problem solution
- Minimum addition | Hackerearth Practice problem
- The magical mountain | Hackerearth Practice problem
- The first overtake | Hackerearth Practice problem
Hackerrank Problems:-
- Playing With Characters | Hackerrank practice problem solution
- Sum and Difference of Two Numbers | hackerrank practice problem solution
- Functions in C | hackerrank practice problem solution
- Pointers in C | hackerrank practice problem solution
- Conditional Statements in C | Hackerrank practice problem solution
- For Loop in C | hackerrank practice problem solution
- Program to find cycle in the graph
- Implementation of singly link list
- Implementation of queue by using link list
- Algorithm of quick sort
- stack by using link list
- program to find preorder post order and inorder of the binary search tree
- Minimum weight of spanning tree
- Preorder, inorder and post order traversal of the tree
,cool phone numbers to call,
,cool numbers copy and paste,
,cool random number generator,
,dollar bill serial number lookup,
,cool looking numbers,
,interesting numbers,
,fancy serial lookup,
,cool number font generator,
2 Comments
Good job sir 👍
ReplyDeleteGood one
ReplyDelete