Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
chore: update lc problems
  • Loading branch information
yanglbme committed Nov 23, 2023
commit 82ff84949fbd1663eb3b9c353b5a546d1764e7b3
88 changes: 88 additions & 0 deletions solution/2900-2999/2941.Maximum GCD-Sum of a Subarray/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# [2941. Maximum GCD-Sum of a Subarray](https://leetcode.cn/problems/maximum-gcd-sum-of-a-subarray)

[English Version](/solution/2900-2999/2941.Maximum%20GCD-Sum%20of%20a%20Subarray/README_EN.md)

## 题目描述

<!-- 这里写题目描述 -->

<p>You are given an array of integers <code>nums</code> and an integer <code>k</code>.</p>

<p>The <strong>gcd-sum</strong> of an array <code>a</code> is calculated as follows:</p>

<ul>
<li>Let <code>s</code> be the sum of all the elements of <code>a</code>.</li>
<li>Let <code>g</code> be the <strong>greatest common divisor</strong> of all the elements of <code>a</code>.</li>
<li>The gcd-sum of <code>a</code> is equal to <code>s * g</code>.</li>
</ul>

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

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> nums = [2,1,4,4,4,2], k = 2
<strong>Output:</strong> 48
<strong>Explanation:</strong> We take the subarray [4,4,4], the gcd-sum of this array is 4 * (4 + 4 + 4) = 48.
It can be shown that we can not select any other subarray with a gcd-sum greater than 48.</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> nums = [7,3,9,4], k = 1
<strong>Output:</strong> 81
<strong>Explanation:</strong> We take the subarray [9], the gcd-sum of this array is 9 * 9 = 81.
It can be shown that we can not select any other subarray with a gcd-sum greater than 81.</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
<li><code>n == nums.length</code></li>
<li><code>1 &lt;= n &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= nums[i] &lt;= 10<sup>6</sup></code></li>
<li><code>1 &lt;= k &lt;= n</code></li>
</ul>

## 解法

<!-- 这里可写通用的实现逻辑 -->

<!-- tabs:start -->

### **Python3**

<!-- 这里可写当前语言的特殊实现逻辑 -->

```python

```

### **Java**

<!-- 这里可写当前语言的特殊实现逻辑 -->

```java

```

### **C++**

```cpp

```

### **Go**

```go

```

### **...**

```

```

<!-- tabs:end -->
80 changes: 80 additions & 0 deletions solution/2900-2999/2941.Maximum GCD-Sum of a Subarray/README_EN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# [2941. Maximum GCD-Sum of a Subarray](https://leetcode.com/problems/maximum-gcd-sum-of-a-subarray)

[中文文档](/solution/2900-2999/2941.Maximum%20GCD-Sum%20of%20a%20Subarray/README.md)

## Description

<p>You are given an array of integers <code>nums</code> and an integer <code>k</code>.</p>

<p>The <strong>gcd-sum</strong> of an array <code>a</code> is calculated as follows:</p>

<ul>
<li>Let <code>s</code> be the sum of all the elements of <code>a</code>.</li>
<li>Let <code>g</code> be the <strong>greatest common divisor</strong> of all the elements of <code>a</code>.</li>
<li>The gcd-sum of <code>a</code> is equal to <code>s * g</code>.</li>
</ul>

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

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> nums = [2,1,4,4,4,2], k = 2
<strong>Output:</strong> 48
<strong>Explanation:</strong> We take the subarray [4,4,4], the gcd-sum of this array is 4 * (4 + 4 + 4) = 48.
It can be shown that we can not select any other subarray with a gcd-sum greater than 48.</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> nums = [7,3,9,4], k = 1
<strong>Output:</strong> 81
<strong>Explanation:</strong> We take the subarray [9], the gcd-sum of this array is 9 * 9 = 81.
It can be shown that we can not select any other subarray with a gcd-sum greater than 81.</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
<li><code>n == nums.length</code></li>
<li><code>1 &lt;= n &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= nums[i] &lt;= 10<sup>6</sup></code></li>
<li><code>1 &lt;= k &lt;= n</code></li>
</ul>

## Solutions

<!-- tabs:start -->

### **Python3**

```python

```

### **Java**

```java

```

### **C++**

```cpp

```

### **Go**

```go

```

### **...**

```

```

<!-- tabs:end -->
2 changes: 1 addition & 1 deletion solution/JAVASCRIPT_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
| 2649 | [嵌套数组生成器](/solution/2600-2699/2649.Nested%20Array%20Generator/README.md) | | 中等 | |
| 2650 | [设计可取消函数](/solution/2600-2699/2650.Design%20Cancellable%20Function/README.md) | | 困难 | |
| 2665 | [计数器 II](/solution/2600-2699/2665.Counter%20II/README.md) | | 简单 | |
| 2666 | [只允许一次函数调用](/solution/2600-2699/2666.Allow%20One%20Function%20Call/README.md) | | 简单 | |
| 2666 | [只允许一次函数调用 44](/solution/2600-2699/2666.Allow%20One%20Function%20Call/README.md) | | 简单 | |
| 2667 | [创建 Hello World 函数](/solution/2600-2699/2667.Create%20Hello%20World%20Function/README.md) | | 简单 | |
| 2675 | [将对象数组转换为矩阵](/solution/2600-2699/2675.Array%20of%20Objects%20to%20Matrix/README.md) | | 困难 | 🔒 |
| 2676 | [节流](/solution/2600-2699/2676.Throttle/README.md) | | 中等 | 🔒 |
Expand Down
3 changes: 2 additions & 1 deletion solution/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2676,7 +2676,7 @@
| 2663 | [字典序最小的美丽字符串](/solution/2600-2699/2663.Lexicographically%20Smallest%20Beautiful%20String/README.md) | `贪心`,`字符串` | 困难 | 第 343 场周赛 |
| 2664 | [巡逻的骑士](/solution/2600-2699/2664.The%20Knight%E2%80%99s%20Tour/README.md) | `数组`,`回溯`,`矩阵` | 中等 | 🔒 |
| 2665 | [计数器 II](/solution/2600-2699/2665.Counter%20II/README.md) | | 简单 | |
| 2666 | [只允许一次函数调用](/solution/2600-2699/2666.Allow%20One%20Function%20Call/README.md) | | 简单 | |
| 2666 | [只允许一次函数调用44](/solution/2600-2699/2666.Allow%20One%20Function%20Call/README.md) | | 简单 | |
| 2667 | [创建 Hello World 函数](/solution/2600-2699/2667.Create%20Hello%20World%20Function/README.md) | | 简单 | |
| 2668 | [查询员工当前薪水](/solution/2600-2699/2668.Find%20Latest%20Salaries/README.md) | `数据库` | 简单 | 🔒 |
| 2669 | [统计 Spotify 排行榜上艺术家出现次数](/solution/2600-2699/2669.Count%20Artist%20Occurrences%20On%20Spotify%20Ranking%20List/README.md) | `数据库` | 简单 | 🔒 |
Expand Down Expand Up @@ -2951,6 +2951,7 @@
| 2938 | [区分黑球与白球](/solution/2900-2999/2938.Separate%20Black%20and%20White%20Balls/README.md) | | 中等 | 第 372 场周赛 |
| 2939 | [最大异或乘积](/solution/2900-2999/2939.Maximum%20Xor%20Product/README.md) | | 中等 | 第 372 场周赛 |
| 2940 | [找到 Alice 和 Bob 可以相遇的建筑](/solution/2900-2999/2940.Find%20Building%20Where%20Alice%20and%20Bob%20Can%20Meet/README.md) | | 困难 | 第 372 场周赛 |
| 2941 | [Maximum GCD-Sum of a Subarray](/solution/2900-2999/2941.Maximum%20GCD-Sum%20of%20a%20Subarray/README.md) | | 困难 | 🔒 |

## 版权

Expand Down
1 change: 1 addition & 0 deletions solution/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -2949,6 +2949,7 @@ Press <kbd>Control</kbd> + <kbd>F</kbd>(or <kbd>Command</kbd> + <kbd>F</kbd> on
| 2938 | [Separate Black and White Balls](/solution/2900-2999/2938.Separate%20Black%20and%20White%20Balls/README_EN.md) | | Medium | Weekly Contest 372 |
| 2939 | [Maximum Xor Product](/solution/2900-2999/2939.Maximum%20Xor%20Product/README_EN.md) | | Medium | Weekly Contest 372 |
| 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 |
| 2941 | [Maximum GCD-Sum of a Subarray](/solution/2900-2999/2941.Maximum%20GCD-Sum%20of%20a%20Subarray/README_EN.md) | | Hard | 🔒 |

## Copyright

Expand Down
2 changes: 1 addition & 1 deletion solution/javascript-summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
- [2649.嵌套数组生成器](/javascript-solution/2600-2699/2649.Nested%20Array%20Generator/README.md)
- [2650.设计可取消函数](/javascript-solution/2600-2699/2650.Design%20Cancellable%20Function/README.md)
- [2665.计数器 II](/javascript-solution/2600-2699/2665.Counter%20II/README.md)
- [2666.只允许一次函数调用](/javascript-solution/2600-2699/2666.Allow%20One%20Function%20Call/README.md)
- [2666.只允许一次函数调用 44](/javascript-solution/2600-2699/2666.Allow%20One%20Function%20Call/README.md)
- [2667.创建 Hello World 函数](/javascript-solution/2600-2699/2667.Create%20Hello%20World%20Function/README.md)
- [2675.将对象数组转换为矩阵](/javascript-solution/2600-2699/2675.Array%20of%20Objects%20to%20Matrix/README.md)
- [2676.节流](/javascript-solution/2600-2699/2676.Throttle/README.md)
Expand Down
3 changes: 2 additions & 1 deletion solution/summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -2717,7 +2717,7 @@
- [2663.字典序最小的美丽字符串](/solution/2600-2699/2663.Lexicographically%20Smallest%20Beautiful%20String/README.md)
- [2664.巡逻的骑士](/solution/2600-2699/2664.The%20Knight%E2%80%99s%20Tour/README.md)
- [2665.计数器 II](/solution/2600-2699/2665.Counter%20II/README.md)
- [2666.只允许一次函数调用](/solution/2600-2699/2666.Allow%20One%20Function%20Call/README.md)
- [2666.只允许一次函数调用44](/solution/2600-2699/2666.Allow%20One%20Function%20Call/README.md)
- [2667.创建 Hello World 函数](/solution/2600-2699/2667.Create%20Hello%20World%20Function/README.md)
- [2668.查询员工当前薪水](/solution/2600-2699/2668.Find%20Latest%20Salaries/README.md)
- [2669.统计 Spotify 排行榜上艺术家出现次数](/solution/2600-2699/2669.Count%20Artist%20Occurrences%20On%20Spotify%20Ranking%20List/README.md)
Expand Down Expand Up @@ -2998,3 +2998,4 @@
- [2938.区分黑球与白球](/solution/2900-2999/2938.Separate%20Black%20and%20White%20Balls/README.md)
- [2939.最大异或乘积](/solution/2900-2999/2939.Maximum%20Xor%20Product/README.md)
- [2940.找到 Alice 和 Bob 可以相遇的建筑](/solution/2900-2999/2940.Find%20Building%20Where%20Alice%20and%20Bob%20Can%20Meet/README.md)
- [2941.Maximum GCD-Sum of a Subarray](/solution/2900-2999/2941.Maximum%20GCD-Sum%20of%20a%20Subarray/README.md)
1 change: 1 addition & 0 deletions solution/summary_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -2998,3 +2998,4 @@
- [2938.Separate Black and White Balls](/solution/2900-2999/2938.Separate%20Black%20and%20White%20Balls/README_EN.md)
- [2939.Maximum Xor Product](/solution/2900-2999/2939.Maximum%20Xor%20Product/README_EN.md)
- [2940.Find Building Where Alice and Bob Can Meet](/solution/2900-2999/2940.Find%20Building%20Where%20Alice%20and%20Bob%20Can%20Meet/README_EN.md)
- [2941.Maximum GCD-Sum of a Subarray](/solution/2900-2999/2941.Maximum%20GCD-Sum%20of%20a%20Subarray/README_EN.md)