High School: Become Human(数学思维)
Year 2118. Androids are in mass production for decades now, and they do all the work for humans. But androids have to go to school to be able to solve creative tasks. Just like humans before.
It turns out that high school struggles are not gone. If someone is not like others, he is bullied. Vasya-8800 is an economy-class android which is produced by a little-known company. His design is not perfect, his characteristics also could be better. So he is bullied by other androids.
One of the popular pranks on Vasya is to force him to compare xyxy with yxyx. Other androids can do it in milliseconds while Vasya's memory is too small to store such big numbers.
Please help Vasya! Write a fast program to compare xyxy with yxyx for Vasya, maybe then other androids will respect him.
On the only line of input there are two integers xx and yy (1≤x,y≤1091≤x,y≤109).
If xy<yxxy<yx, then print '<' (without quotes). If xy>yxxy>yx, then print '>' (without quotes). If xy=yxxy=yx, then print '=' (without quotes).
5 8
>
10 3
<
6 6
=
In the first example 58=5⋅5⋅5⋅5⋅5⋅5⋅5⋅5=39062558=5⋅5⋅5⋅5⋅5⋅5⋅5⋅5=390625, and 85=8⋅8⋅8⋅8⋅8=3276885=8⋅8⋅8⋅8⋅8=32768. So you should print '>'.
In the second example 103=1000<310=59049103=1000<310=59049.
In the third example 66=46656=6666=46656=66.
题目意思:给你两个数x, y, 比较 x^y 和 y ^ x 的大小
解题思路:首先看看这个x^y的表达式是不是很熟悉,是不是就是高数里面的幂指函数,那么想一想我们在幂指函数求导等操作中是怎么做的,没错就是取对数!!利用ln将幂指函数抬起!!
例如:xy = e ln (x^y) = e y(ln x) 。(也可以使用lg,以10为底的对数,把下面代码里面的log10()改为log()即可)
这里我在对log ()函数进行一下说明。
double log (double); 以e为底的对数
double log10 (double);c++中自然对数函数:log(N) 以10为底:log10(N)但没有以2为底的函数但是可以用换底公式解 决:log2(N)=log10(N)/log10(2)
1 #include<cstdio> 2 #include<cmath> 3 const int eps=1e-9; 4 int main() 5 { 6 int x,y; 7 double a,b; 8 scanf("%d%d",&x,&y); 9 a=log10(x)*y; 10 b=log10(y)*x; 11 if(fabs(a-b)<=eps) 12 { 13 printf("=\n"); 14 } 15 else if(a-b<0) 16 { 17 printf("<\n"); 18 } 19 else 20 { 21 printf(">\n"); 22 } 23 return 0; 24 }
本文作者:王陸
本文链接:https://www.cnblogs.com/wkfvawl/p/9565221.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步