小白一枚,python解法,共同学习,一起进步。

Problem 1: Multiples of 3 and 5

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.

Find the sum of all the multiples of 3 or 5 below 1000.

解题思路:

找出所有3和5的倍数,不超过最大数n,去重求和即可。

 l = []  # 存放3和5倍数的数
n = 1000 # 最大数
for i in range(1, n):
if 3*i >= n: # 如果大于最大数,终止
break
l.append(3*i)
for i in range(1, n):
if 5*i >= n:
break
l.append(5*i)
l = set(l) # 去重,譬如15 30之类的
print(sum(l))

%time %run ol001.py
233168
Wall time: 2 ms

Problem 1: Multiples of 3 and 5的更多相关文章

  1. Python练习题 029:Project Euler 001:3和5的倍数

    开始做 Project Euler 的练习题.网站上总共有565题,真是个大题库啊! # Project Euler, Problem 1: Multiples of 3 and 5 # If we ...

  2. 用PYTHON练练一些算法

    网上一个专门用来给新手练算法的: http://projecteuler.net/problem=1 Multiples of 3 and 5 Problem 1 Published on Frida ...

  3. 2020.4.6--UCF Local Programming Contest 2017的正式赛

    Problem A : Electric Bill 题目大意:进行电量分级制收费,1000kwh及以下一档收费,1000kwh以上按另一档收费,给出每个人的电量总额,问每人应支付多少钱. 思路:基础i ...

  4. (Problem 1)Multiples of 3 and 5

    If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The ...

  5. 2012Chhengdu K - Yet Another Multiple Problem

    K - Yet Another Multiple Problem Time Limit:20000MS     Memory Limit:65536KB     64bit IO Format:%I6 ...

  6. Multiples of 3 and 5

    #include<stdio.h> int main(void){ int n1, n2,n3; n1=333*(3+999)/2; n2=199*(5+995)/2; n3=66*(15 ...

  7. algorithm@ Sieve of Eratosthenes (素数筛选算法) & Related Problem (Return two prime numbers )

    Sieve of Eratosthenes (素数筛选算法) Given a number n, print all primes smaller than or equal to n. It is ...

  8. Yet Another Multiple Problem(bfs好题)

    Yet Another Multiple Problem Time Limit : 40000/20000ms (Java/Other)   Memory Limit : 65536/65536K ( ...

  9. hdu4474 Yet Another Multiple Problem

    Yet Another Multiple Problem Description There are tons of problems about integer multiples. Despite ...

随机推荐

  1. 小程序之 fixed定位下scroll-view左右滚动失效

    红框为悬浮 左右可以滑动 效果如下⬇️ 悬浮把最外层position:fixed;top:0;这个时候上面的导航就可以悬浮 但是会出现左右滑动不了的情况 这是因为我没给设置宽度 这个时候我们把包着sc ...

  2. ps使用经验

  3. power shell 脚本了解

    1. https://www.cnblogs.com/xianglongsdu/p/5832984.html 2.https://www.cnblogs.com/lsdb/p/9531338.html ...

  4. NetSec2019 20165327 Exp4 恶意代码分析

    NetSec2019 20165327 Exp4 恶意代码分析 一.实践目标 1.监控你自己系统的运行状态,看有没有可疑的程序在运行. 2.分析一个恶意软件,就分析Exp2或Exp3中生成后门软件:分 ...

  5. xlwt模块的使用

    前记:Python处理表格时会用到xlwt和xlrd模块 xlwt设置行高:row sheet.row(2).set_style(xlwt.easyxf('font:height 440;')) 13 ...

  6. RxJava2

    原文地址 这可能是最好的RxJava 2.x 入门教程(一) 这可能是最好的RxJava 2.x 入门教程(二) 这可能是最好的RxJava 2.x 入门教程(三) 这可能是最好的RxJava 2.x ...

  7. Java语言中的奇淫技巧

    variable length parameter list(可变长度参数列表) 很久之前了解过有这么一种写法,但转眼即忘.今天在公司项目的代码里看到,有点小惊讶,写这代码的同事还是有点水平的...

  8. 面试题3--数组中的重复数字(new数组的新写法)

    总是忘了一些条件的判断,比如非空或者其他之类. #include<iostream> using namespace std; int Frepeat(int num[],int leng ...

  9. http请求requestUtils

    import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import ...

  10. requests库/爬取zhihu表情包

    先学了requests库的一些基本操作,简单的爬了一下. 用到了requests.get()方法,就是以GET方式请求网页,得到一个Response对象.不加headers的话可能会400error所 ...