1. Story Teller
In Tarnasha movie, there is a kid named Ved who lives in Manali. He loves hearing stories from a story-teller who lives in their neighbourhood. The story-teller charges Y rupees for every story he tells and for every Z stories which
Ved can remember and summarize on a later day, he tells an additional story Ved can summarize a story only once and he never forgets a story We need to calculate the maximum number of stories which Ved can hear
Sample Input
3
10 2 5
12 4 4
6 2 2
Sample Output
6
3
5
spends his 10 rupees to hear 5 stories at a cost of Rs 2/story. He summarizes all of them to hear an additional story Total 6 Le spends his 12 rupees to hear 3 stories at a cost of Rs.4/story Total 3 spends his 6 rupees to hear 3 stories at a cost of Rs.2/story He then
arizes 2 of the stories and save one for later to hear his 4th story n summanizes this story and the one he saved from the previous
You are learning cryptography and as a challenge, your friend gave you this problem to decode. You are given an encoded string. To decode the string, the encoded string is read one character at a time and the following steps are taken
• If the character read is a letter, that letter is written in the decoded string
If the character read is a digit, say d, the entire decoded string is
repeatedly written d-1 more times in total
Finally, given an integer k, you need to return the ith letter from the decoded
string.
The character on the ith index of the decoded strings consists of lowercase English letters and digits 2 through
Sample Input
ha22
5
Sample Output
h
The deccoded string is "hahahaha"
The 5th letter is "h"
Friend A wants to surprise Friend B on her birthday She ha a bar which has a colection of beads with alphabets onthem Friend A wants to build a neckace consisting of herfrends name and her name This shall be her gift on her birthday and she wants to construct the longest necklace
possible however only using her name or her friends name or a combination of both their names. Can you help Friend A come up with the longest length of the string that sheneeds to order from Pincode App?
Note: The letter once piciced up, can't be repeated
First line represents the Box.
Second line represents the friend A 's name
Third line represents the friend B 's name
The length of the longest string that can be constructed
Box consists only of uppercase English letters.
1< Box length « 10e7
1 <= FriendA.length « 10e5
1 <= FriendB.length « 10e5
ABCRNMXYZANBCA
ANNA
RAM
Sample Output
7
One can pick letters ANAN to form ANNA and
'RMA to form RAM
So the longest letter of the string is 7.
Bob is given a non-negative number N and he is expected to bring taht number to 0 . He can perform any of the 2 Operations on N in each move
1) If we take 2 integers and and b where N = a*b then we can change N = max(a,b)
2 Decrease the value of N by 1
Determine the minimum number of moves required to reduce the value of N to 0
Input - 3
Output - 3
3 ---> 2 ---> 1 ----> 0
SAMPLE INPUT
3
SAMPLE OUTPUT
3
3 --->2 --->1 -->0
///REDUCE TO ZERO
#include <bits/stdc++.h>
using namespace std;
vector<int>f(int n){
vector<int>v;
for(int i=2;i<=sqrt(n);i++)if(n%i==0)v.push_back(n/i);
return v;
}
int main() {
int n;
cin>>n;
vector<int>dp(n+1,INT_MAX);
dp[0]=0;
dp[1]=1;
dp[2]=2;
for(int i=2;i<=n;i++){
dp[i]=dp[i-1]+1;
for(auto fac :f(i)){
dp[i]=min(dp[i] , 1 + dp[fac]);
}
}
cout<<dp[n]<<endl;
return 0;
}
// QNO-1 STORY TELLER
#include <bits/stdc++.h>
using namespace std;
int f(int a, int b, int c){
int ts = a/b;
int cs = ts;
while(cs >= c){
int ns = cs/c;
cs = cs%c;
cs+=ns;
ts+=ns;
}
return ts;
}
int main(){
int t;
cin>>t;
while(t--){
int a, b, c;
cin>>a>>b>>c;
cout<<f(a, b, c)<<endl;
}
}