You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求X<2^N时使(A^X)*(B^X)乘积最大的模1e9+7结果

寻找使(AX)*(BX)最大的X并计算模值

给定整数A、B和N,需找到满足X < 2^N的整数X,使得(A ^ X)与(B ^ X)的乘积最大,最终返回该最大乘积对10^9+7取模的结果。

示例

A = 4
B = 6
N = 3

选择X=3时,(A ^ X)=7,(B ^ X)=5,乘积为35,是所有可能中的最大值。

实现代码

int limit = (1<<n) - 1;
int MOD = 1_000_000_007;
int maxProd = 1;
for(int i = 1; i <= limit; i++){
  int x1 = (A^i);
  int x2 = (B^i);
  maxProd = max(maxProd, (x1*x2) % MOD);
}
return maxProd;

内容的提问来源于stack exchange,提问作者Tuhin Dutta

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 05:25:14