<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                # 數組中范圍的乘積 > 原文: [https://www.geeksforgeeks.org/products-ranges-array/](https://www.geeksforgeeks.org/products-ranges-array/) 給定大小為 N 的數組 A []。解決 Q 個查詢。 在模 P 下找到[L,R]范圍內的乘積(P 為質數)。 **示例**: ``` Input : A[] = {1, 2, 3, 4, 5, 6} L = 2, R = 5, P = 229 Output : 120 Input : A[] = {1, 2, 3, 4, 5, 6}, L = 2, R = 5, P = 113 Output : 7 ``` **暴力** 對于每個查詢,遍歷[L,R]范圍內的每個元素并計算模 P 下的乘積。這將以`O(n)`回答每個查詢。 ## C++ ```cpp // Product in range? // Queries in O(N) #include <bits/stdc++.h> using namespace std; // Function to calculate? // Product in the given range. int calculateProduct(int A[], int L,? ?????????????????????int R, int P) { ????// As our array is 0 based? ????// as and L and R are given ????// as 1 based index. ????L = L - 1; ????R = R - 1; ????int ans = 1; ????for (int i = L; i <= R; i++)? ????{ ????????ans = ans * A[i]; ????????ans = ans % P; ????} ????return ans; } // Driver code int main() { ????int A[] = { 1, 2, 3, 4, 5, 6 }; ????int P = 229; ????int L = 2, R = 5; ????cout << calculateProduct(A, L, R, P) ?????????<< endl; ????L = 1, R = 3; ????cout << calculateProduct(A, L, R, P)? ?????????<< endl; ????return 0; } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看