Physical Address

304 North Cardinal St.
Dorchester Center, MA 02124

Covid Spread CodeChef Solution – Queslers

Problem: Covid Spread CodeChef Solution

A disease is spreading through ChefLand!

The disease spreads as follows:

  • At the end of day 00, a single person is infected with the disease.
  • During the next 1010 days, the number of infected people doubles each day, until the disease has spread to all people in ChefLand.
  • From day 1111 onwards, the number of infected people triples each day, until the disease has spread to all people in ChefLand.

You are given the population of ChefLand NN and a day DD. How many people in ChefLand are infected at the end of day DD?

Input Format

  • The first line of input contains a single integer TT, denoting the number of test cases. The description of TT test cases follows.
  • Each test case consists of a single line containing two space-separated integers NN and DD — the population of ChefLand and the day for which you need to find the number of infected people, respectively.

Output Format

  • For each test case, print one line containing a single integer — the number of infected people in ChefLand at the end of day DD.

Constraints

  • 1≤T≤3001≤T≤300
  • 1≤N≤1081≤N≤108
  • 0≤D≤1080≤D≤108

Subtasks

Subtask 1 (30 points): D≤20D≤20

Subtask 2 (70 points): Original constraints

Sample Input 1 

4
100 3
2000 10
6000 11
10 11

Sample Output 1 

8
1024
3072
10

Explanation

Test Case 1:

  • At the end of day 11, the number of infected people is 2×1=22×1=2.
  • At the end of day 22, the number of infected people is 2×2=42×2=4.
  • At the end of day 33, the number of infected people is 2×4=82×4=8.

Test Case 2: Following the rules in the statement, it can be seen that at the end of day 1010, the total number of infected people is 10241024.

Test Case 3: Note that starting at day 1111, the number of infected people triples each day, 3×1024=30723×1024=3072.

Test Case 4: At the end of day 33, the number of infected people is 88. Since there are only 1010 people in ChefLand (which is less than 2×8=162×8=16), at the end of day 44 all people in ChefLand are infected and thus the number of infected people is 1010 for all days from day 44 onwards, including day 1111.

Covid Spread CodeChef Solution in C

#include <stdio.h>

#include <math.h>
int main() {
    // Write C code here
    int w;
    long long int p,d,r; 
    scanf("%d",&w);
    while(w--)
    {
        scanf("%lld %lld ",&p,&d);
        
        if(d<=10)
        {r=pow(2,d);
        if(r>p)
        r=p;}
        else
        {   r=pow(2,10);
            for(int i=11;i<=d;i++)
        {
            r=r*3;
            if(r>p)
            {r=p;
            break;
            }
        }}
        printf("%lld",r);
        printf("\n");
    }
    
    return 0;
}

Covid Spread CodeChef Solution in C++

#include <bits/stdc++.h>
using namespace std;

int main() {
	long long int t,i,s=1;
	cin>>t;
	while(t--){
	   long long int a,b,s=1;
	   cin>>a>>b;
	   for(int i=1;i<=b&&s<a;i++){
if(i<11) s*=2;
else s*=3;
}
if(s>=a) s=a;
cout<<s<<endl;

 	}
	return 0;
}

Covid Spread CodeChef Solution in Java

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
  public static void main (String[] args) throws java.lang.Exception
  {
      Scanner s = new Scanner(System.in);
      int t = s.nextInt();
      while(t-- != 0){
          long n = s.nextLong();
          long d = s.nextLong();
          
          long sum = 1;
          for(long i = 1; i<=d; i++){
              if(i<=10){
                  sum = sum * 2;
                  if(sum > n){
                      sum = n;
                      break;
                  }
              }
              else
              {
                    sum = sum * 3;
                    if(sum > n)
                    {
                        sum = n;
                        break;
                  }
              }
          }
          System.out.println(sum);
      }
      s.close();
  }
}

Covid Spread CodeChef Solution in Python

try:
    t = int(input())
    for i in range(t):
        n,d = map(int,input().split(" "))
        # print(n,d)
        # print(type(n))
        
        if d<=10:
            ans = 2**d
            if ans <= n:
                print(ans)
            else:
                print(n)
        elif d>10:
            ans = 1024
            if ans <= n:
                if d>20:
                    print(n)
                else:
                    ans = ans*(3**(d-10))
                    if ans <= n:
                        print(ans)
                    else:
                        print(n)
                    # print(ans)
                # if ans <= n:
                #     print(ans)
                # else:
                #     print(n)
            else:
                print(n)
except: pass
Covid Spread CodeChef Solution Review:

In our experience, we suggest you solve this Covid Spread CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

Covid Spread Problem is available on Hacker Rank for Free, if you are stuck anywhere between a compilation, just visit Queslers to get Covid Spread CodeChef Solution.

Conclusion:

I hope this Covid Spread CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Hacker Rank, Leetcode, Codechef, Codeforce Solution.

This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.

Keep Learning!

More CodeChef Solutions >>

Olympics Ranking CodeChef Solution

Problem Difficulties CodeChef Solution

Chef and Bulb Invention CodeChef Solution

Array Filling CodeChef Solution

Special Triplets CodeChef Solution

Leave a Reply

Your email address will not be published. Required fields are marked *