#include <iostream>
#include <cmath>
#include <cstring>
const int MAXN = 300;
using namespace std;
/* 大数类,重载流运算,== < > 运算 */
class Bigint
{
public:
friend istream& operator >> (istream& input, Bigint& b);
friend ostream& operator << (ostream& output, Bigint& b);
friend bool operator == (Bigint& b1, Bigint& b2);
friend Bigint operator * (Bigint& b1, Bigint& b2);
friend bool operator < (Bigint& b1, Bigint& b2);
int length;
private:
char num[MAXN + 10];
};
istream& operator >> (istream& input, Bigint& b)
{
char buf[MAXN + 10];
input.getline(buf, MAXN + 10);
int m = 0;
for(int i = strlen(buf) - 1; i >= 0; i--)
{
b.num[m++] = buf[i];
}
b.num[m] = 0;
b.length = m;
return input;
}
ostream& operator << (ostream& output, Bigint& b)
{
for(int i = b.length - 1; i >= 0; i--)
{
cout << b.num[i];
}
return output;
}
bool operator < (Bigint& b1, Bigint& b2)
{
if(b1.length < b2.length)
{
return true;
}
else if(b1.length > b2.length)
{
return false;
}
else
{
for(int i = b1.length - 1; i >= 0; i--)
{
if(b1.num[i] < b2.num[i])
{
return true;
}
else if(b1.num[i] > b2.num[i])
{
return false;
}
}
return false;
}
}
bool operator == (Bigint& b1, Bigint& b2)
{
if(b1.length != b2.length)
{
return false;
}
else
{
for(int i = 0; i < b1.length; i++)
{
if(b1.num[i] != b2.num[i])
{
return false;
}
}
return true;
}
}
/* 高精度乘法 */
Bigint operator * (Bigint& b1, Bigint& b2)
{
Bigint t;
int temp[MAXN + 10] = {};
int i, j;
for(i = 0; i < b1.length; i++)
{
for(j = 0; j < b2.length; j++)
{
temp[i + j] += (b1.num[i] - '0') * (b2.num[j] - '0');
}
}
for(i = 0; i < MAXN + 10; i++)
{
if(temp[i] >= 10)
{
int ten = temp[i] / 10;
temp[i] %= 10;
temp[i + 1] += ten;
}
}
for(i = MAXN; i >= 0; i--)
{
if(temp[i] != 0)
{
break;
}
}
t.length = i + 1;
for(i = 0; i < t.length; i++)
{
t.num[i] = temp[i] + '0';
}
return t;
}
int main()
{
int nTest;
cin >> nTest;
cin.ignore();
for(; nTest != 0; nTest--)
{
Bigint num1, num2;
cin >> num1 >> num2;
int x = 1;
Bigint result;
if(num1 < num2)
{
result = num1;
while(result < num2)
{
x++;
result = result * num1;
}
cout << x - 1 << endl;
}
if(num1 == num2 || num2 < num1) // 这种情况下 0 一定满足条件
{
cout << 0 << endl;
}
cin.ignore(); // 滤除一个换行符
}
return 0;
}
计算对数
最新推荐文章于 2021-06-17 16:18:31 发布