Covid Spread COVSPRD Solution Codechef

Covid Spread COVSPRD Solution

A disease is spreading through ChefLand! The disease spreads as follows:

  • At the end of day 0, a single person is infected with the disease.
  • During the next 10 days, the number of infected people doubles each day, until the disease has spread to all people in ChefLand.
  • From day 11 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 N and a day D. How many people in ChefLand are infected at the end of day D?

Input Format

  • The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows.
  • Each test case consists of a single line containing two space-separated integers N and D 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 D.

Constraints

  • 1≤T≤300
  • 1≤N≤108
  • 0≤D≤108

Subtasks

Subtask 1 (30 points): D≤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 1, the number of infected people is 2×1=2.
  • At the end of day 2, the number of infected people is 2×2=4.
  • At the end of day 3, the number of infected people is 2×4=8.

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

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

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

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

Leave a Comment

eleven + 17 =