Chef and Demonetisation Codechef Solution

ByBrokenprogrammers

Dec 13, 2022

Hello Programmers In this post, you will know how to solve the Chef and Demonetisation Codechef Solution.

One more thing to add, don’t directly look for the solutions, first try to solve the problems of Codechef by yourself. If you find any difficulty after trying several times, then you can look for solutions.

Problem

In a country called Chef Land, there was a lot of monetary fraud, so Chefu, the head of the country, decided to choose new denominations of the local currency ― all even-valued coins up to an integer NN should exist. After a few days, a citizen complained that there was no way to create an odd value, so Chefu decided that he should also introduce coins with value 1. Formally, you are given an integer NN; for v=1 and each even positive integer v≤N, coins with value v exist.

You are also given an integer S. To handle transactions quickly, find the minimum number of coins needed to pay a price SS.

Input

• The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
• The first and only line of each test case contains two space-separated integers S and N.

Output

For each test case, print a single line containing one integer ― the minimum number of coins.

Constraints

• 1≤T≤10,0001≤T≤10,000
• 1≤S≤1091≤S≤109
• 2≤N≤1092≤N≤109
• NN is even

Subtask #1 (100 points): original constraints

```4
2 2
1 14
30 10
31 4
```

```1
1
3
9
```

Explanation

Example case 1: One coin with value 2 is sufficient.

Example case 2: We need to use one coin with value 1.

Example case 3: We need 3 coins, each with value 10.

Example case 4: We can use seven coins with value 4, one coin with value 2 and one coin with value 1.

Chef and Demonetisation CodeChef Solutions 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 sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
int s=sc.nextInt();
int n=sc.nextInt();
int count=0;
if(s%2==1){
s--;
count++;
}
if(s%n==0){
System.out.println(count+(s/n));
}
else {
System.out.println(count+(s/n)+1);
}
}
}
}
```

Chef and Demonetisation CodeChef Solutions in CPP

```#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define MAXSIZE 101
#define endl "\n"
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while(t--)
{
ll S, N;
cin >> S >> N;
ll countOfCoins = 0 ;
if(S < N)
{
if(S%2==0)
cout << 1 << endl;
else if(S==1)
cout << 1 << endl;
else
cout << 2 << endl;
}
else
{
ll countOfCoins = 0 ;
if(S%2==1)
{
countOfCoins++;
S--;
}
countOfCoins = countOfCoins + (S / N) ;
if(S%N!=0)
countOfCoins+=1;
cout << countOfCoins << endl;
}
}
}```

Chef and Demonetisation CodeChef Solutions in Python

```t=int(input())
for i in range(0,t):
count=0
s,n=map(int,input().split())
while s>0:
count=count+(s//n)
s=s%n
if s>=2:
if s%2==0:
n=s
else:
n=s-1
else:
n=1
print(count) ```

Disclaimer: The above Problem (Chef and Demonetisation) is generated by CodeChef but the solution is provided by BrokenProgrammers. This tutorial is only for Educational and Learning purpose.

Note:- I compile all programs, if there is any case program is not working and showing an error please let me know in the comment section. If you are using adblocker, please disable adblocker because some functions of the site may not work correctly.