Below is the program I've written to find the exponent of 6, but I this its giving wrong output or I may be wrong somewhere, I'm unable to figure out here.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ll t;
cin>>t;
cout<<log(t)/log(6)<<"\n";
cout<<floor(log(t)/log(6))<<"\n";
cout<<ceil(log(t)/log(6));
return 0;
}
Input:-
216
Output:-
3
3
4
Since 216
can be written as 6*6*6
, so whether there is ceil or floor the output should be 3 in all three cases.
Answering to my own question, this problem can be solved by setting small precision(here up to 2 decimal digits), below is the program for the same.
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
cout<<log(t)/log(6)<<"\n";
cout<<floor((floor(log(t)/log(6)*100.0)/100.0))<<"\n";
cout<<ceil((floor(log(t)/log(6)*100.0)/100.0));
return 0;
}