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
following example to prove his point.
Lets suppose the maximum price of an item is 5$ then we can make coins of ($1, 52, 53, 54, 55) to purchase any item ranging from $1 till 55.
Now Manisha, being a keen observer suggested that we could actually minimize the number of coins required and gave following distribution (
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.
Answers
Answer:#include <iostream>
using namespace std;
int main() {
int t,den,a,ct;
cin>>t;
while(t--){
cin>>den;
a=1,ct=0;
while(den>0){
den-=a;
a=a+1;
ct++;
}
cout<<ct<<"\n";
}
}
Explanation:first while will iterate for test cases then we will subtract our denomination till it passes 0.
Language using :- Python Programming
Program :-
t=int(input())
if t>=1 and t<=100:
while(t>0):
sum=0
total=0
n=int(input())
if n>=1 and n<=5000:
l=list(range(1,n+1))
for i in l:
if sum!=n+1 and sum<n+1:
sum=sum+i
total=total+1
if sum>n+1 or sum==n:
sum=sum-i
total=total-1
if sum==n+1:
print(total)
break
t=t-1
Input :-
2
10
5
Output :-
4
3
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