<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>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # 計算特殊矩陣中等于 x 的條目 > 原文: [https://www.geeksforgeeks.org/count-entries-equal-to-x-in-a-special-matrix/](https://www.geeksforgeeks.org/count-entries-equal-to-x-in-a-special-matrix/) 您將得到 n 階方矩陣(matrix [] []),其中 matrix [i] [j] = i * j。 查找具有等于給定數字 x 的條目的像元數。 注意:矩陣的索引從 1 開始,即 1 < = i,j < = n。 **示例**: ``` Input : matrix[][] = {1, 2, 3, 4, 2, 4, 6, 8, 3, 6, 9, 12, 4, 8, 12, 16} x = 4 Output : 3 Input : matrix[][] = {1, 2, 3, 4, 2, 4, 6, 8, 3, 6, 9, 12, 4, 8, 12, 16} x = 12 Output : 2 ``` **簡單方法**是遍歷整個矩陣并檢查像元值是否等于給定的 x,然后相應地增加計數值。 這種方法的時間復雜度很高,等于 O(n ^ 2)。 ``` // traverse and check whole matrix for (int i=1; i<=n ; i++) { for (int j=1; j<=n; j++) if (i * j == x) count++; } // return count return count; ``` **有效方法**僅查找給定 x 的因子數量在 0 到 x 之間,并且那些因子(包括除數和商)必須小于或等于 n(矩陣的階數)。 在這種情況下,時間復雜度將為`O(n)`。 ``` // traverse and find the factors for (int i=1; i<=n && i<=x ; i++) { // x%i == 0 means i is factor of x // x/i <= n means i and j are <= n (for i*j=x) if ( x/i <= n && x%i ==0) count++; } // return count return count; ``` ## C++ ```cpp // CPP program for counting number of cell? // equals to given x #include<bits/stdc++.h> using namespace std; // function to count factors as number of cell int count (int n, int x) { ????int count == 0; ????// traverse and find the factors ????for (int i=1; i<=n && i<=x ; i++) ????{ ????????// x%i == 0 means i is factor of x ????????// x/i <= n means i and j are <= n (for i*j=x) ????????if ( x/i <= n && x%i ==0) ????????????count++; ????} ????// return count? ????return count; } // driver program int main() { ????int n = 8; ????// we can manually assume matrix of order 8*8 ????// where mat[i][j] = i*j , 0<i,j<=n ????int x =? 24; ????cout << count(n, x); ????return 0; }? ``` ## Java ```java // Java program for counting number of // cell equals to given x class GFG { ????// function to count factors as? ????// number of cell ????static int count (int n, int x) ????{ ????????int count = 0; ????????// traverse and find the factors ????????for (int i = 1; i <= n && i <= x ; ????????????????????????????????????i++) ????????{ ????????????// x%i == 0 means i is factor ????????????// of x. x/i <= n means i and ????????????// j are <= n (for i*j=x) ????????????if ( x / i <= n && x % i == 0) ????????????????count++; ????????} ????????// return count? ????????return count; ????} ????// driver program ????public static void main(String args[]) ????{ ????????int n = 8; ????????// we can manually assume matrix? ????????// of order 8*8 where? ????????// mat[i][j] = i*j , 0<i,j<=n ????????int x = 24; ????????System.out.println(count(n, x)); ????} } /*This code is contributed by Danish kaleem*/ ``` ## Python3 ```py # Python 3 program for counting? # number of cell equals to given x? # function to count factors? # as number of cell? def count(n, x): ????cnt = 0 ????# traverse and find the factors? ????for i in range(1, n + 1): ????????# // x%i == 0 means i is factor of x? ????????# x/i <= n means i and j are <= n (for i*j=x)? ????????if i <= x: ????????????if x // i <= n and x % i == 0: ????????????????cnt += 1 ????return cnt # Driver code n = 8 x = 24 print(count(n, x)) # This code is contributed by Shrikant13 ``` ## C# ```cs // C# program for counting number // of cell equals to given x using System;? class GFG { ????// function to count factors as? ????// number of cell ????static int count (int n, int x) { ????????int count = 0; ????????// traverse and find the factors ????????for (int i = 1; i <= n &&? ?????????????i <= x ; i++) ????????{ ????????????// x%i == 0 means i is factor ????????????// of x. x/i <= n means i and ????????????// j are <= n (for i*j=x) ????????????if ( x / i <= n && x % i == 0) ????????????????count++; ????????} ????????// return count? ????????return count; ????} ????// Driver Code ????public static void Main() ????{ ????????int n = 8; ????????// we can manually assume matrix? ????????// of order 8*8 where? ????????// mat[i][j] = i*j , 0<i,j<=n ????????int x = 24; ????????Console.Write(count(n, x)); ????} } // This code is contributed by Nitin Mittal. ``` ## PHP ```php <?php // PHP program for counting? // number of cell equals to // given x // function to count factors // as number of cell function c_ount ( $n, $x) { ????$Count = 0; ????// traverse and find the factors ????for ( $i = 1; $i <= $n and? ??????????????????$i <= $x ; $i++) ????{ ????????// x%i == 0 means i is? ????????// factor of x x/i <= n?? ????????// means i and j are? ????????// <= n (for i*j=x) ????????if ( $x / $i <= $n and? ??????????????????$x % $i == 0) ????????????$Count++; ????} ????// return count? ????return $Count; } // Driver Code $n = 8; // we can manually assume? // matrix of order 8*8 // where mat[i][j] = i*j ,? // 0<i,j<=n $x = 24; echo c_ount($n, $x); // This code is contributed by anuj_67\. ?> ``` **輸出**: ``` 4 ``` 本文由 [**Shivam Pradhan(anuj_charm)**](http://www.facebook.com/ma5ter6it) 提供。 如果您喜歡 GeeksforGeeks 并希望做出貢獻,則還可以使用 [tribution.geeksforgeeks.org](http://www.contribute.geeksforgeeks.org) 撰寫文章,或將您的文章郵寄至 tribution@geeksforgeeks.org。 查看您的文章出現在 GeeksforGeeks 主頁上,并幫助其他 Geeks。
                  <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>

                              哎呀哎呀视频在线观看