D. Pow

这篇博客讨论了一种快速比较两个指数表达式大小的方法。通过利用对数来简化比较,例如2^3与3^2,博主解决了老师给出的挑战,即判断100^{99}

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题干

form QLU p1010
D. Pow
Description

As we all now that there’s a easy way to describe some same consecutive factors multiply each other which is POW.

For example, 2×2×2=232\times2\times2=2^32×2×2=23 and 3×3=323\times3=3^23×3=32 and it is easy to see that 23<3223<3223<32.

Now, your math teacher just gave you a problem in his class which is 10099100^{99}10099 9910099^{100}99100 which one is bigger? There are many ways to solve that and you solved it quickly. When you told the answer to your teach, he seemed to be unsatisfactory about that and he continued to asked the pow problems like that, which is given four positive integers a,b,c,da,b,c,da,b,c,d could you tell that which one is bigger between aba^bab and cdc^dcd or they are equal.
16121439447368.png

picture: some answers in the Internet
In C, you may use the function pow to calculate the answer:

pow(2,3)=8
pow(3,2)=9

Input

First line of the input contains one positive integer T(1≤T≤105)T (1\le T\le 10^5)T(1≤T≤105) indicating the number of the test cases.

Next TTT lines, each line contains four positive integers a,b,c,d(1≤a,b,c,d≤109)a,b,c,d (1\le a,b,c,d\le10^9)a,b,c,d(1≤a,b,c,d≤109)
Output

Four each test case:
if ab>cdab>cdab>cd print LEFT
else if ab=cdab=cdab=cd print EQUAL
else print RIGHT
Examples
Input
复制

3
3 2 2 3
100 99 99 100
2 4 4 2

Output
复制

LEFT
RIGHT
EQUAL

代码

#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
int main(){
    int t;
    double a,b,c,d;
    cin>>t;
    while (t--)
    {
        scanf("%lf %lf %lf %lf",&a,&b,&c,&d);
        double lf=b*log(a),ri=d*log(c);
        if(lf-ri>1e-8) printf("LEFT\n");//精度控制在1e-8之间
        else if(fabs(lf-ri)<=1e-8) printf("EQUAL\n");
        else printf("RIGHT\n");
       
        /* co
        de */
    }

     system("pause");
        return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值