Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save devteampentagon/8caa13292bee7c5c99240a612b034d95 to your computer and use it in GitHub Desktop.

Select an option

Save devteampentagon/8caa13292bee7c5c99240a612b034d95 to your computer and use it in GitHub Desktop.
How Many Digits in X to the Power Y
#include <bits/stdc++.h>
#define MEM(a,b) memset((a),(b),sizeof(a))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIn(a,b) ((a)<(b)?(a):(b))
#define MIn4(a,b,c,d) MIn(MIn(MIn(a,b),c),d)
#define In freopen("In.txt", "r", stdin);
#define Out freopen("out.txt", "w", stdout);
#define i64 long long
#define u64 long long unsigned
#define sz 1000000
using namespace std;
//digitsInPower() function returns how many
//Digits we will get in x^y
int digitsInPower(int x,int y)
{
return (int)(floor((y*1.0)*(log10(x))) + 1);
}
int main()
{
int x,y;
while(cin >> x >> y)
cout << digitsInPower(x,y) << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment