3770. Largest Prime from Consecutive Prime Sum Medium
1/**
2 * [3770] Largest Prime from Consecutive Prime Sum
3 *
4 * You are given an integer n.
5 * Return the largest <span data-keyword="prime-number">prime number</span> less than or equal to n that can be expressed as the sum of one or more consecutive prime numbers starting from 2. If no such number exists, return 0.
6 *
7 * <strong class="example">Example 1:
8 * <div class="example-block">
9 * Input: <span class="example-io">n = 20</span>
10 * Output: <span class="example-io">17</span>
11 * Explanation:
12 * The prime numbers less than or equal to n = 20 which are consecutive prime sums are:
13 *
14 *
15 * 2 = 2
16 *
17 *
18 * 5 = 2 + 3
19 *
20 *
21 * 17 = 2 + 3 + 5 + 7
22 *
23 *
24 * The largest is 17, so it is the answer.
25 * </div>
26 * <strong class="example">Example 2:
27 * <div class="example-block">
28 * Input: <span class="example-io">n = 2</span>
29 * Output: <span class="example-io">2</span>
30 * Explanation:
31 * The only consecutive prime sum less than or equal to 2 is 2 itself.
32 * </div>
33 *
34 * Constraints:
35 *
36 * 1 <= n <= 5 * 10^5
37 *
38 */
39pub struct Solution {}
40
41// problem: https://leetcode.com/problems/largest-prime-from-consecutive-prime-sum/
42// discuss: https://leetcode.com/problems/largest-prime-from-consecutive-prime-sum/discuss/?currentPage=1&orderBy=most_votes&query=
43
44// submission codes start here
45
46impl Solution {
47 pub fn largest_prime(n: i32) -> i32 {
48 0
49 }
50}
51
52// submission codes end
53
54#[cfg(test)]
55mod tests {
56 use super::*;
57
58 #[test]
59 fn test_3770() {
60 }
61}
62Back
© 2026 bowen.ge All Rights Reserved.