当前位置: 首页 > news >正文

LeetCode每日一题——2652. Sum Multiples

文章目录

    • 一、题目
    • 二、题解

一、题目

Given a positive integer n, find the sum of all integers in the range [1, n] inclusive that are divisible by 3, 5, or 7.

Return an integer denoting the sum of all numbers in the given range satisfying the constraint.

Example 1:

Input: n = 7
Output: 21
Explanation: Numbers in the range [1, 7] that are divisible by 3, 5, or 7 are 3, 5, 6, 7. The sum of these numbers is 21.
Example 2:

Input: n = 10
Output: 40
Explanation: Numbers in the range [1, 10] that are divisible by 3, 5, or 7 are 3, 5, 6, 7, 9, 10. The sum of these numbers is 40.
Example 3:

Input: n = 9
Output: 30
Explanation: Numbers in the range [1, 9] that are divisible by 3, 5, or 7 are 3, 5, 6, 7, 9. The sum of these numbers is 30.

Constraints:

1 <= n <= 103

二、题解

class Solution {
public:int sumOfMultiples(int n) {int sum = 0;for(int i = 1;i <= n;i++){if(i % 3 == 0 || i % 5 == 0 || i % 7 == 0) sum += i;}return sum;}
};
http://www.lryc.cn/news/195809.html

相关文章:

  • Python问答题(更新中)
  • 服务器中了locked勒索病毒怎么办,勒索病毒解密,数据恢复
  • 游游的字母串 (环形数组两点之间的位置)
  • Flink的ResourceManager详解(一)
  • Tornado 可以使用 nginx 提供负载均衡
  • Golang 面向对象编程 多态
  • WLAN 无线案例(华为AC控制器配置模板)
  • 精美的早安问候语,暖心祝福,开心每一天
  • 嵌入式养成计划-41----C++ auto--lambda表达式--C++中的数据类型转换--C++标准模板库(STL)--list--C++文件操作
  • 全局事件总线
  • 通讯网关软件026——利用CommGate X2ORACLE-U实现OPC UA数据转入ORACLE
  • RAII与智能指针
  • 易云维智慧工业云平台助力广西国企培育数字产业化平台,打造数字化产业生态
  • 【密码学】第三章、分组密码
  • 宁夏企业过等保选哪家测评机构好?选哪家堡垒机好?
  • Vue绑定style和class 对象写法
  • 使用vue-sign插件
  • python究竟可以用来做些什么
  • Segment Anything(论文解析)
  • @ConditionalOnProperty 用法
  • 如何选择超声波清洗机、超声波清洗机排行榜
  • 大家这么喜欢这件羽绒服的吗?眼光太好啦
  • pytorch 入门(二)
  • 2023年国赛-大数据应用开发(师生同赛)_赛项规程样题解析
  • MNE系列教程1——MNE的安装与基本绘图
  • 黑马JVM总结(三十六)
  • 【React】01-React的入门
  • 【C语言进阶】自定义类型:结构体,枚举,联合
  • Sklearn 聚类算法的性能评估
  • 9月最新外贸进出口数据出来了,外贸整体向好