直接取对数
注意精度 1e-6 会wa 要1e-9
#include <iostream>
#include <cstring>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <cstdio>
#include <stdio.h>
#include<queue>
#include<math.h>
using namespace std;
#define ll long long
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
double x,y;
cin>>x>>y;
double ans=(y/x)*log(x)/log(y);
if(ans-1<0)cout<<'<'<<endl;
else if(ans-1>1e-9)cout<<'>'<<endl;
else cout<<'='<<endl;
}
本文介绍了一种通过取对数比较两个数幂次大小的方法,并提供了C++代码实现。该方法通过计算两个数的对数比来判断其幂次的大小关系,确保了计算精度,避免了直接计算大幂次可能导致的溢出问题。
1273

被折叠的 条评论
为什么被折叠?



