Skip to content

Commit 82ff849

Browse files
committed
chore: update lc problems
1 parent 67e06dd commit 82ff849

File tree

8 files changed

+176
-4
lines changed

8 files changed

+176
-4
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# [2941. Maximum GCD-Sum of a Subarray](https://leetcode.cn/problems/maximum-gcd-sum-of-a-subarray)
2+
3+
[English Version](/solution/2900-2999/2941.Maximum%20GCD-Sum%20of%20a%20Subarray/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>You are given an array of integers <code>nums</code> and an integer <code>k</code>.</p>
10+
11+
<p>The <strong>gcd-sum</strong> of an array <code>a</code> is calculated as follows:</p>
12+
13+
<ul>
14+
<li>Let <code>s</code> be the sum of all the elements of <code>a</code>.</li>
15+
<li>Let <code>g</code> be the <strong>greatest common divisor</strong> of all the elements of <code>a</code>.</li>
16+
<li>The gcd-sum of <code>a</code> is equal to <code>s * g</code>.</li>
17+
</ul>
18+
19+
<p>Return <em>the <strong>maximum gcd-sum</strong> of a subarray of</em> <code>nums</code> <em>with at least</em> <code>k</code> <em>elements.</em></p>
20+
21+
<p>&nbsp;</p>
22+
<p><strong class="example">Example 1:</strong></p>
23+
24+
<pre>
25+
<strong>Input:</strong> nums = [2,1,4,4,4,2], k = 2
26+
<strong>Output:</strong> 48
27+
<strong>Explanation:</strong> We take the subarray [4,4,4], the gcd-sum of this array is 4 * (4 + 4 + 4) = 48.
28+
It can be shown that we can not select any other subarray with a gcd-sum greater than 48.</pre>
29+
30+
<p><strong class="example">Example 2:</strong></p>
31+
32+
<pre>
33+
<strong>Input:</strong> nums = [7,3,9,4], k = 1
34+
<strong>Output:</strong> 81
35+
<strong>Explanation:</strong> We take the subarray [9], the gcd-sum of this array is 9 * 9 = 81.
36+
It can be shown that we can not select any other subarray with a gcd-sum greater than 81.</pre>
37+
38+
<p>&nbsp;</p>
39+
<p><strong>Constraints:</strong></p>
40+
41+
<ul>
42+
<li><code>n == nums.length</code></li>
43+
<li><code>1 &lt;= n &lt;= 10<sup>5</sup></code></li>
44+
<li><code>1 &lt;= nums[i] &lt;= 10<sup>6</sup></code></li>
45+
<li><code>1 &lt;= k &lt;= n</code></li>
46+
</ul>
47+
48+
## 解法
49+
50+
<!-- 这里可写通用的实现逻辑 -->
51+
52+
<!-- tabs:start -->
53+
54+
### **Python3**
55+
56+
<!-- 这里可写当前语言的特殊实现逻辑 -->
57+
58+
```python
59+
60+
```
61+
62+
### **Java**
63+
64+
<!-- 这里可写当前语言的特殊实现逻辑 -->
65+
66+
```java
67+
68+
```
69+
70+
### **C++**
71+
72+
```cpp
73+
74+
```
75+
76+
### **Go**
77+
78+
```go
79+
80+
```
81+
82+
### **...**
83+
84+
```
85+
86+
```
87+
88+
<!-- tabs:end -->
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# [2941. Maximum GCD-Sum of a Subarray](https://leetcode.com/problems/maximum-gcd-sum-of-a-subarray)
2+
3+
[中文文档](/solution/2900-2999/2941.Maximum%20GCD-Sum%20of%20a%20Subarray/README.md)
4+
5+
## Description
6+
7+
<p>You are given an array of integers <code>nums</code> and an integer <code>k</code>.</p>
8+
9+
<p>The <strong>gcd-sum</strong> of an array <code>a</code> is calculated as follows:</p>
10+
11+
<ul>
12+
<li>Let <code>s</code> be the sum of all the elements of <code>a</code>.</li>
13+
<li>Let <code>g</code> be the <strong>greatest common divisor</strong> of all the elements of <code>a</code>.</li>
14+
<li>The gcd-sum of <code>a</code> is equal to <code>s * g</code>.</li>
15+
</ul>
16+
17+
<p>Return <em>the <strong>maximum gcd-sum</strong> of a subarray of</em> <code>nums</code> <em>with at least</em> <code>k</code> <em>elements.</em></p>
18+
19+
<p>&nbsp;</p>
20+
<p><strong class="example">Example 1:</strong></p>
21+
22+
<pre>
23+
<strong>Input:</strong> nums = [2,1,4,4,4,2], k = 2
24+
<strong>Output:</strong> 48
25+
<strong>Explanation:</strong> We take the subarray [4,4,4], the gcd-sum of this array is 4 * (4 + 4 + 4) = 48.
26+
It can be shown that we can not select any other subarray with a gcd-sum greater than 48.</pre>
27+
28+
<p><strong class="example">Example 2:</strong></p>
29+
30+
<pre>
31+
<strong>Input:</strong> nums = [7,3,9,4], k = 1
32+
<strong>Output:</strong> 81
33+
<strong>Explanation:</strong> We take the subarray [9], the gcd-sum of this array is 9 * 9 = 81.
34+
It can be shown that we can not select any other subarray with a gcd-sum greater than 81.</pre>
35+
36+
<p>&nbsp;</p>
37+
<p><strong>Constraints:</strong></p>
38+
39+
<ul>
40+
<li><code>n == nums.length</code></li>
41+
<li><code>1 &lt;= n &lt;= 10<sup>5</sup></code></li>
42+
<li><code>1 &lt;= nums[i] &lt;= 10<sup>6</sup></code></li>
43+
<li><code>1 &lt;= k &lt;= n</code></li>
44+
</ul>
45+
46+
## Solutions
47+
48+
<!-- tabs:start -->
49+
50+
### **Python3**
51+
52+
```python
53+
54+
```
55+
56+
### **Java**
57+
58+
```java
59+
60+
```
61+
62+
### **C++**
63+
64+
```cpp
65+
66+
```
67+
68+
### **Go**
69+
70+
```go
71+
72+
```
73+
74+
### **...**
75+
76+
```
77+
78+
```
79+
80+
<!-- tabs:end -->

solution/JAVASCRIPT_README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
| 2649 | [嵌套数组生成器](/solution/2600-2699/2649.Nested%20Array%20Generator/README.md) | | 中等 | |
3535
| 2650 | [设计可取消函数](/solution/2600-2699/2650.Design%20Cancellable%20Function/README.md) | | 困难 | |
3636
| 2665 | [计数器 II](/solution/2600-2699/2665.Counter%20II/README.md) | | 简单 | |
37-
| 2666 | [只允许一次函数调用](/solution/2600-2699/2666.Allow%20One%20Function%20Call/README.md) | | 简单 | |
37+
| 2666 | [只允许一次函数调用 44](/solution/2600-2699/2666.Allow%20One%20Function%20Call/README.md) | | 简单 | |
3838
| 2667 | [创建 Hello World 函数](/solution/2600-2699/2667.Create%20Hello%20World%20Function/README.md) | | 简单 | |
3939
| 2675 | [将对象数组转换为矩阵](/solution/2600-2699/2675.Array%20of%20Objects%20to%20Matrix/README.md) | | 困难 | 🔒 |
4040
| 2676 | [节流](/solution/2600-2699/2676.Throttle/README.md) | | 中等 | 🔒 |

solution/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2676,7 +2676,7 @@
26762676
| 2663 | [字典序最小的美丽字符串](/solution/2600-2699/2663.Lexicographically%20Smallest%20Beautiful%20String/README.md) | `贪心`,`字符串` | 困难 | 第 343 场周赛 |
26772677
| 2664 | [巡逻的骑士](/solution/2600-2699/2664.The%20Knight%E2%80%99s%20Tour/README.md) | `数组`,`回溯`,`矩阵` | 中等 | 🔒 |
26782678
| 2665 | [计数器 II](/solution/2600-2699/2665.Counter%20II/README.md) | | 简单 | |
2679-
| 2666 | [只允许一次函数调用](/solution/2600-2699/2666.Allow%20One%20Function%20Call/README.md) | | 简单 | |
2679+
| 2666 | [只允许一次函数调用44](/solution/2600-2699/2666.Allow%20One%20Function%20Call/README.md) | | 简单 | |
26802680
| 2667 | [创建 Hello World 函数](/solution/2600-2699/2667.Create%20Hello%20World%20Function/README.md) | | 简单 | |
26812681
| 2668 | [查询员工当前薪水](/solution/2600-2699/2668.Find%20Latest%20Salaries/README.md) | `数据库` | 简单 | 🔒 |
26822682
| 2669 | [统计 Spotify 排行榜上艺术家出现次数](/solution/2600-2699/2669.Count%20Artist%20Occurrences%20On%20Spotify%20Ranking%20List/README.md) | `数据库` | 简单 | 🔒 |
@@ -2951,6 +2951,7 @@
29512951
| 2938 | [区分黑球与白球](/solution/2900-2999/2938.Separate%20Black%20and%20White%20Balls/README.md) | | 中等 | 第 372 场周赛 |
29522952
| 2939 | [最大异或乘积](/solution/2900-2999/2939.Maximum%20Xor%20Product/README.md) | | 中等 | 第 372 场周赛 |
29532953
| 2940 | [找到 Alice 和 Bob 可以相遇的建筑](/solution/2900-2999/2940.Find%20Building%20Where%20Alice%20and%20Bob%20Can%20Meet/README.md) | | 困难 | 第 372 场周赛 |
2954+
| 2941 | [Maximum GCD-Sum of a Subarray](/solution/2900-2999/2941.Maximum%20GCD-Sum%20of%20a%20Subarray/README.md) | | 困难 | 🔒 |
29542955

29552956
## 版权
29562957

solution/README_EN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2949,6 +2949,7 @@ Press <kbd>Control</kbd> + <kbd>F</kbd>(or <kbd>Command</kbd> + <kbd>F</kbd> on
29492949
| 2938 | [Separate Black and White Balls](/solution/2900-2999/2938.Separate%20Black%20and%20White%20Balls/README_EN.md) | | Medium | Weekly Contest 372 |
29502950
| 2939 | [Maximum Xor Product](/solution/2900-2999/2939.Maximum%20Xor%20Product/README_EN.md) | | Medium | Weekly Contest 372 |
29512951
| 2940 | [Find Building Where Alice and Bob Can Meet](/solution/2900-2999/2940.Find%20Building%20Where%20Alice%20and%20Bob%20Can%20Meet/README_EN.md) | | Hard | Weekly Contest 372 |
2952+
| 2941 | [Maximum GCD-Sum of a Subarray](/solution/2900-2999/2941.Maximum%20GCD-Sum%20of%20a%20Subarray/README_EN.md) | | Hard | 🔒 |
29522953

29532954
## Copyright
29542955

solution/javascript-summary.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
- [2649.嵌套数组生成器](/javascript-solution/2600-2699/2649.Nested%20Array%20Generator/README.md)
2525
- [2650.设计可取消函数](/javascript-solution/2600-2699/2650.Design%20Cancellable%20Function/README.md)
2626
- [2665.计数器 II](/javascript-solution/2600-2699/2665.Counter%20II/README.md)
27-
- [2666.只允许一次函数调用](/javascript-solution/2600-2699/2666.Allow%20One%20Function%20Call/README.md)
27+
- [2666.只允许一次函数调用 44](/javascript-solution/2600-2699/2666.Allow%20One%20Function%20Call/README.md)
2828
- [2667.创建 Hello World 函数](/javascript-solution/2600-2699/2667.Create%20Hello%20World%20Function/README.md)
2929
- [2675.将对象数组转换为矩阵](/javascript-solution/2600-2699/2675.Array%20of%20Objects%20to%20Matrix/README.md)
3030
- [2676.节流](/javascript-solution/2600-2699/2676.Throttle/README.md)

solution/summary.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2717,7 +2717,7 @@
27172717
- [2663.字典序最小的美丽字符串](/solution/2600-2699/2663.Lexicographically%20Smallest%20Beautiful%20String/README.md)
27182718
- [2664.巡逻的骑士](/solution/2600-2699/2664.The%20Knight%E2%80%99s%20Tour/README.md)
27192719
- [2665.计数器 II](/solution/2600-2699/2665.Counter%20II/README.md)
2720-
- [2666.只允许一次函数调用](/solution/2600-2699/2666.Allow%20One%20Function%20Call/README.md)
2720+
- [2666.只允许一次函数调用44](/solution/2600-2699/2666.Allow%20One%20Function%20Call/README.md)
27212721
- [2667.创建 Hello World 函数](/solution/2600-2699/2667.Create%20Hello%20World%20Function/README.md)
27222722
- [2668.查询员工当前薪水](/solution/2600-2699/2668.Find%20Latest%20Salaries/README.md)
27232723
- [2669.统计 Spotify 排行榜上艺术家出现次数](/solution/2600-2699/2669.Count%20Artist%20Occurrences%20On%20Spotify%20Ranking%20List/README.md)
@@ -2998,3 +2998,4 @@
29982998
- [2938.区分黑球与白球](/solution/2900-2999/2938.Separate%20Black%20and%20White%20Balls/README.md)
29992999
- [2939.最大异或乘积](/solution/2900-2999/2939.Maximum%20Xor%20Product/README.md)
30003000
- [2940.找到 Alice 和 Bob 可以相遇的建筑](/solution/2900-2999/2940.Find%20Building%20Where%20Alice%20and%20Bob%20Can%20Meet/README.md)
3001+
- [2941.Maximum GCD-Sum of a Subarray](/solution/2900-2999/2941.Maximum%20GCD-Sum%20of%20a%20Subarray/README.md)

solution/summary_en.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2998,3 +2998,4 @@
29982998
- [2938.Separate Black and White Balls](/solution/2900-2999/2938.Separate%20Black%20and%20White%20Balls/README_EN.md)
29992999
- [2939.Maximum Xor Product](/solution/2900-2999/2939.Maximum%20Xor%20Product/README_EN.md)
30003000
- [2940.Find Building Where Alice and Bob Can Meet](/solution/2900-2999/2940.Find%20Building%20Where%20Alice%20and%20Bob%20Can%20Meet/README_EN.md)
3001+
- [2941.Maximum GCD-Sum of a Subarray](/solution/2900-2999/2941.Maximum%20GCD-Sum%20of%20a%20Subarray/README_EN.md)

0 commit comments

Comments
 (0)