1969. 数组元素的最小非零乘积
题目链接:1969. 数组元素的最小非零乘积
代码如下:
//参考:https://leetcode.cn/problems/minimum-non-zero-product-of-the-array-elements/solutions/936621/tan-xin-ji-qi-shu-xue-zheng-ming-by-endl-uumv
class Solution {
public:
long long pow(long long x,int p)
{
x%=mod;
long long res=1;
while(p--)
{
res=res*x%mod;
x=x*x%mod;
}
return res;
}
int minNonZeroProduct(int p)
{
long long k=(1LL<<p)-1;
return k%mod*pow(k-1,p-1)%mod;
}
private:
const int mod=1'000'000'007;
};