The problem solvers have found a new island for coding and named it as philaland
Answers
Answered by
17
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 value becomes 5, and the 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
Attachments:
Similar questions