Byte to Bit Codechef Solution

Byte to Bit Codechef Solution: Hello coders, today we are going to solve Byte to Bit Codechef Solution.

Codechef solutions

Problem

In the magical land of Byteland, there are three kinds of citizens:

  • a Bit – 2ms2ms after a Bit appears, it grows up and becomes a Nibble (i.e. it disappears and a Nibble appears)
  • a Nibble – 8ms8ms after a Nibble appears, it grows up and becomes a Byte
  • a Byte – 16ms16ms after a Byte appears, it grows up, splits into two Bits and disappears

Chef wants to know the answer to the following question: what would the population of Byteland be immediately before the time NmsNms if only 1 Bit appeared at time 0ms0ms?

Help him and find the population (number of citizens) of each type.

Input

  • The first line of the input contains a single integer TT denoting the number of test cases. The description of TT test cases follows.
  • The first and only line of each test case contains a single integer NN.

Output

For each test case, print a single line containing three space-separated integers — the number of Bits, Nibbles and Bytes.

Constraints

  • 1≤T≤1041≤T≤104
  • 1≤N≤1,6001≤N≤1,600

Subtasks

Subtask #1 (25 points): 1≤N≤1401≤N≤140

Subtask #2 (75 points): original constraints

Sample Input 1 

2
2
3

Sample Output 1 

1 0 0
0 1 0

Explanation

Immediately before the time 2ms2ms, there is only one Bit. At 2ms2ms, this Bit grows up, so immediately before 3ms3ms, there is only one Nibble in Byteland.

Byte to Bit  – CodeChef Solution in JAVA

import java.util.Scanner;
class Byte_to_Bit {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int t = input.nextInt();
        while(t-- > 0) {
            int n = input.nextInt();
            long ans = 1;
            while(n > 26) {
                ans *= 2;
                n -= 26;
            }
            if (n<=2) {
                System.out.println(ans + " 0" + " 0");
            } else if (n>2 && n<= 10) {
                System.out.println("0 " + ans + " 0");
            } else {
                System.out.println("0 " + "0 " + ans);
            }
        }
        input.close();
    }
}

Byte to Bit   – CodeChef Solution in CPP

#include <iostream>
using namespace std;
#define ll long int
int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--)
	{
	    ll n;
	    cin>>n;
	    ll x=1,y=0,z=0;
	    ll count=0;
	    while(1)
	    {
	        count+=2;
	        if(count>=n)
	        {
	            break;
	        }
	        else
	        {
	            y=x;
	            x=0;
	            count+=8;
	            if(count>=n)
	            {
	                break;
	            }
	            else
	            {
	                z=y;
	                y=0;
	                count+=16;
	                if(count>=n)
	                {
	                    break;
	                }
	                else
	                {
	                    x=2*z;
	                    z=0;
	                }
	            }
	        }
	    }
	    cout<<x<<" "<<y<<" "<<z<<endl;
	}
	return 0;
}

Byte to Bit- CodeChef Solution in Python

for _ in range(int(input())):
    n=int(input())
    if(n%26==0):
        a=n//26-1
    else:
        a=n//26
    a=2**a
    b=n%26
    if b in range(1,3):
        print(a,0,0)
    elif b in range(3,11):
        print(0,a,0)
    else:
        print(0,0,a)

Disclaimer: The above Problem (Byte to Bit ) is generated by CodeChef but the solution is provided by  Chase2learn.This tutorial is only for Educational and Learning purpose.

Leave a Comment