Food Chain: FODCHAIN

link : https://www.codechef.com/CU1PP0007/problems/FODCHAIN


A great deal of energy is lost as metabolic heat when the organisms from one trophic level are consumed by the next level.

Suppose in Chefland the energy reduces by a factor of K, i.e, if initially, the energy is X, then the transfer of energy to the next tropic level is ⌊XK⌋. This limits the length of foodchain which is defined to be the highest level receiving non-zero energy.

E is the energy at the lowest tropic level. Given E and K for an ecosystem, find the maximum length of foodchain.

Note: ⌊x⌋ denoted the floor function, and it returns the greatest integer that is less than or equal to x (i.e rounds down to the nearest integer). For example, ⌊1.4⌋=1, ⌊5⌋=5, ⌊−1.5⌋=−2, ⌊−3⌋=−3 , ⌊0⌋=0.

Solution:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int

int main() {

	ll t;
	cin>>t;
		while(t--)
		{
	    ll E,K;
	    ll ans=1;
	    cin>>E>>K;
	    while(E/K!=0){
	        ans++;
	        E=E/K;

	    }
	    cout<<ans<<endl;
	}
	return 0;
}
The content uploaded on this website is for reference purposes only. Please do it yourself first.