链接:https://www.nowcoder.com/acm/contest/90/L
来源:牛客网

 

输入x,a,y,b,(1<=x,a,y,b<=10^9)判断x^a是否等于y^b

前面同时加log,即判断alogx==blogy

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 int main()
 4 {
 5     int n;
 6     int x,a,y,b;
 7     scanf("%d",&n);
 8     while(n--)
 9     {
10         scanf("%d%d%d%d",&x,&a,&y,&b);
11         if(fabs(a*log(x)-b*log(y))<0.1)
12             printf("Yes\n");
13         else
14             printf("No\n");
15     }
16     return 0;
17 }

也可以余上很大的素数

 

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 const int mod = 1e9+7;
 4 typedef long long LL;
 5 LL pow(LL a, LL b)
 6 {
 7     LL res = 1;
 8     while(b)
 9     {
10         if(b&1) res=(res*a)%mod;
11         a=(a*a)%mod;
12         b>>=1;
13     }
14     return res;
15 }
16 int main()
17 {
18     LL t, a, b, x, y;
19     cin>>t;
20     while(t--)
21     {
22         scanf("%lld%lld%lld%lld", &x, &a, &y, &b);
23         if(pow(x, a) == pow(y, b))
24             puts("Yes");
25         else
26             puts("No");
27     }
28     return 0;
29 }

 

相关文章:

  • 2021-06-25
  • 2022-12-23
  • 2022-12-23
  • 2021-10-25
  • 2022-12-23
  • 2021-10-28
  • 2022-12-23
  • 2021-07-14
猜你喜欢
  • 2021-10-27
  • 2021-10-01
  • 2021-09-07
  • 2021-08-12
  • 2022-02-13
  • 2021-11-07
相关资源
相似解决方案