-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodechefFoodChain.cpp
More file actions
71 lines (58 loc) · 1.34 KB
/
CodechefFoodChain.cpp
File metadata and controls
71 lines (58 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
Codechef Starter Jul-2021
Explanation
TestCase 1: The energy at first level is 5 units. For the second level energy becomes ⌊53⌋=1 units.
So the length of foodchain is 2 since from the next level onwards 0 units of energy will be received.
TestCase 3: The energy at different levels is:
Level 1- 10 units
Level 2- ⌊102⌋=5 units
Level 3- ⌊52⌋=2 units
Level 4- ⌊22⌋=1 units
Level 5- ⌊12⌋=0 units
So the answer is 4, since it is the last level to receive non-zero energy.
3
5 3
6 7
10 2
2
1
4
*/
#include <iostream>
using namespace std;
int main() {
int testcase;
int a;
int b;
cin>>testcase;
while(testcase--)
{
int ans=0;
cin>>a>>b;
while(a!=0)
{
ans++;
a=a/b;
}
cout<<ans;
}
}
/*
Explanation
TestCase 1: The energy at first level is 5 units. For the second level energy becomes ⌊53⌋=1 units.
So the length of foodchain is 2 since from the next level onwards 0 units of energy will be received.
TestCase 3: The energy at different levels is:
Level 1- 10 units
Level 2- ⌊102⌋=5 units
Level 3- ⌊52⌋=2 units
Level 4- ⌊22⌋=1 units
Level 5- ⌊12⌋=0 units
So the answer is 4, since it is the last level to receive non-zero energy.
3
5 3
6 7
10 2
2
1
4
*/