Computer Science, asked by shivamraghav96, 8 months ago

Philaland Coin Problem Description The problem solvers have found a new Island for coding and named it as Philaland. These smart people were given a task to make purchase of items at the Island easier by distributing various coins with different value. Manish has come up with a solution that if we make coins category starting from $1 till the maximum price of item present on Island, then we can purchase any item easily. He added following example to prove his point. Lets suppose the maximum price of an item is 5$ then we can make coins of {$1, $2, $3, $4, $5} to purchase any item ranging from $1 till $5. Now Manisha, being a keen observer suggested that we could actually minimize the number of coins required and gave following distribution {$1, $2, $3}. According to him any item can be purchased one time ranging from $1 to $5. Everyone was impressed with both of them. Your task is to help Manisha come up with minimum number of denominations for any arbitrary max price in Philaland. Constraints 1<=T<=100 1<=N<=5000 Input Format First line contains an integer T denoting the number of test cases. Next T lines contains an integer N denoting the maximum price of the item present on Philaland. Output For each test case print a single line denoting the minimum number of denominations of coins required. Timeout 1 Test Case Example 1 Input 2 10 5 Output 4 3 Explanation For test case 1, N=10. According to Manish {$1, $2, $3,... $10} must be distributed. But as per Manisha only {$1, $2, $3, $4} coins are enough to purchase any item ranging from $1 to $10. Hence minimum is 4. Likewise denominations could also be {$1, $2, $3, $5}. Hence answer is still 4. For test case 2, N=5. According to Manish {$1, $2, $3, $4, $5} must be distributed. But as per Manisha only {$1, $2, $3} coins are enough to purchase any item ranging from $1 to $5. Hence minimum is 3. Likewise denominations could also be {$1, $2, $4}. Hence answer is still 3.

Answers

Answered by poojan
1

Philaland Coin Problem

Language used : Python Programming

Program :

no_of_testcases=int(input())

l=[]

for i in range(no_of_testcases):

   l.append(int(input()))

for i in l:

   count=0

   while i>=1:

       i=i//2

       count=count+1

   print(count)

Input :

2

10

5

Output :

4

3

Explanation :

  • If the amount needed = 10, minimum no.of coins needed = {1,2,3,4}

       If the amount needed = 5, minimum no.of coins needed = {1,2,3}

  • If we see, the coin count is close to the nearest 2's power + 1.

  • The denomination goes as 10 on entering the loop checks if it is greater than or equal to 1. Yes? Now, i becomes 5 and count increases by 1.

  • Next 5>=1 is True, i=5//2 which is 2 that now stores in i, making count 2

  • 2>=1, true. i=2//2 and the value 1 is stored in i and count becomes 3

  • 1>=1, true. i=1//2 and the result 0 stores in i, count becomes 4.

  • 0>=1, False. Loop terminates and count=4 prints. Similarly, the computation happens with 5.

Learn more :

1) Printing all the palindromes formed by a palindrome word.

brainly.in/question/19151384

2) Indentation is must in python. Know more about it at :

brainly.in/question/17731168

3) Write a Python function sumsquare(l) that takes a nonempty list of integers and returns a list [odd,even], where odd is the sum of squares all the odd numbers in l and even is the sum of squares of all the even numbers in l

brainly.in/question/15473120

Attachments:
Similar questions