Skip to content

Commit

Permalink
Create 1969.Minimum-Non-Zero-Product-of-the-Array-Elements.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
wisdompeak authored Aug 15, 2021
1 parent 2302b95 commit c3ad25d
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using LL = long long;
class Solution {
LL M = 1e9+7;
public:
LL quickMul(LL x, LL N)
{
if (N == 0) return 1;
LL y = quickMul(x, N / 2);
return N % 2 == 0 ? (y * y % M) : (y * y % M * x % M);
}

int minNonZeroProduct(int p)
{
LL a = (1ll<<(p-1)) - 1;
LL x = ((1ll<<p)-1) % M;
LL ret = quickMul(x-1, a) * x % M;

return ret;
}
};

0 comments on commit c3ad25d

Please sign in to comment.