Covid Spread COVSPRD Solution Codechef

Codechef Covid Spread COVSPRD 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.

January Long Challenge 2022
January Long Challenge 2022

Solution

Program: Covid Spread COVSPRD Solution in C++

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

int main(){
    int t;
    cin>>t;
    while(t--){
        
        int n,d;
        cin>>n>>d;
        
        long long ans=1; // for day 0
        
        if(d==0) {}
        else if( d <=10 ) {
            ans=pow(2,d);
        }
        else if(d>10 and  d < 30){
            ans = pow(2,10)*pow(3,d-10);
        }
        else ans=n;
        
        if(ans>=n)
        cout<<n<<endl;
        else
        cout<<ans<<endl;
    }
    
    return 0;
}

Program: Covid Spread COVSPRD Solution in Java

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

class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner scn=new Scanner(System.in);
		int t=scn.nextInt();
		while(t-->0){
		   int n=scn.nextInt();
		   int d=scn.nextInt();
		   long ans=1;
		   
		   if(d>10){
		      ans=(int)Math.pow(2,10);
		      d=d-10;
		      ans*=(int)Math.pow(3,d);
		   }else{
		      ans=(int)Math.pow(2,d);
		   }
		   if(ans>n)
		   ans=n;
		   System.out.println(ans);
		}
	}
}

Program: Covid Spread COVSPRD Solution in Python

t= int(input())
ans=0
while t!=0:
    nd = [int(x) for x in input().split()]
    if nd[1]>56:
        ans=nd[0]
    elif nd[1]>10:
        ans=2**10*3**(nd[1]-10)
    else:
        ans=2**nd[1]
    if ans>nd[0]:
        print(nd[0])
    else:
        print(ans)    
    t-=1

January Long Challenge 2022 Solution

December Long Challenge 2021 Solution

Leave a Comment