Problem 1: Multiples of 3 and 5
小白一枚,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的更多相关文章
- Python练习题 029:Project Euler 001:3和5的倍数
开始做 Project Euler 的练习题.网站上总共有565题,真是个大题库啊! # Project Euler, Problem 1: Multiples of 3 and 5 # If we ...
- 用PYTHON练练一些算法
网上一个专门用来给新手练算法的: http://projecteuler.net/problem=1 Multiples of 3 and 5 Problem 1 Published on Frida ...
- 2020.4.6--UCF Local Programming Contest 2017的正式赛
Problem A : Electric Bill 题目大意:进行电量分级制收费,1000kwh及以下一档收费,1000kwh以上按另一档收费,给出每个人的电量总额,问每人应支付多少钱. 思路:基础i ...
- (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 ...
- 2012Chhengdu K - Yet Another Multiple Problem
K - Yet Another Multiple Problem Time Limit:20000MS Memory Limit:65536KB 64bit IO Format:%I6 ...
- 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 ...
- 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 ...
- Yet Another Multiple Problem(bfs好题)
Yet Another Multiple Problem Time Limit : 40000/20000ms (Java/Other) Memory Limit : 65536/65536K ( ...
- hdu4474 Yet Another Multiple Problem
Yet Another Multiple Problem Description There are tons of problems about integer multiples. Despite ...
随机推荐
- VBoxManage
虚拟机名称 centos6.9-1 centos6.9-2 centos6.9-3 使用命令开机 虚拟机 VBoxManage startvm 'centos6.9-1' 正常启动 VBoxManag ...
- php list()函数
说明: (PHP 4, PHP 5, PHP 7) list — 把数组中的值赋给一组变量 像 array() 一样,这不是真正的函数,而是语言结构. list() 可以在单次操作内就为一组变量赋值. ...
- threejs 草场足球运动视角(三)
这次要模拟的场景如下图:就是在绿草地上足球的运动,并且视角会随着足球的运动发生变化,同时整个草地的视角也会旋转. 接下来,我们就对各个元素进行分析: 1,草地 用PlaneGeometry在三维空间里 ...
- 爬坑之路---Google map
google.maps.event.adddDomListen(window, 'load', callback);当文档流中所有的dom加载完成后,执行回调函数,可以不用在script中使用defe ...
- js if判断示例
){ ){ console.log("%0 pass") }else{ $(,v,function() { fla=; }); } }){ ){ console.log(" ...
- C++_day7_继承
#include <iostream> using namespace std; class Human{ public: Human(string const& name, in ...
- UI组件--element-ui--Upload多组件自定义上传
需求: 提交详细信息的表单, 并上传对应图片(如下图), 后台接口要求表单数据和图片需要一次上传完成.. 分析: 实际上, 每个element-ui Upload组件都应发送一次请求, 很明显不符合我 ...
- 实验八 <FBG> 基于原型的团队项目需求调研与分析
<FBG>团队项目原型设计:http://www.cnblogs.com/ymm3/p/9012534.html GitHub的链接地址:https://github.com/FBGfbg ...
- Servlet之Filter
一 .过滤器(filter) 处于客户端与服务器资源文件之间的一道过滤网,在访问资源文件之前,通过一系列的过滤器对请求进行修改.判断等,把不符合规则的请求在中途拦截或修改.也可以对响应进行过滤,拦截或 ...
- 雷林鹏分享:jQuery EasyUI 数据网格 - 自定义排序
jQuery EasyUI 数据网格 - 自定义排序 如果默认的排序行为不满足您的需求,您可以自定义数据网格(datagrid)的排序行为. 最基础的,用户可以在列上定义一个排序函数,函数名是 sor ...