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 ...
随机推荐
- linux中centros6.7安装php5.6,httpd-2.2.19(web产品化)遇到的问题总结
前段时间在公司实习,web系统产品化的过程踩了很多坑,在这边总结一下,由于对linux不是很懂,全是自己一步步一个一个问题解决的 1,查看系统中是否安装apache,php,mysql环境 Apach ...
- sourcetree,创建工作流报错:Fatal: Not a gitflow-enabled repo yet. Please run 'git flow init' first.-》解决办法
1.打开项目下.git/config文件,或者如下图操作: 2.打开config文件以后,删除所有 [gitflow *条目并保存文件 3.关闭并重新打开sourcetree 4.仓库->Git ...
- P2678 跳石头
传送门 思路: 二分跳跃的最短距离 mid .暴力判断如果有两个石头直接的距离小于 mid ,就把这个石头拿走.如果拿走的石头数目 cnt ≤ m,说明二分的答案可行,ans = mid,接着二分更短 ...
- VGG
2019-04-08 13:30:58 VGG模型是2014年ILSVRC竞赛的第二名,第一名是GoogLeNet.但是VGG模型在多个迁移学习任务中的表现要优于googLeNet.而且,从图像中提取 ...
- es6中promise ALL Race Resolve Reject finish的实现
function mypromise(func){ this.statue = "pending"; this.data = null; this.resolveCallback ...
- android异步任务处理(网络等耗时操作)
在实际应用中经常会遇到比较耗时任务的处理,比如网络连接,数据库操作等情况时,如果这些操作都是放在主线程(UI线程)中,则会造成UI的假死现象(android4.0后也不许放在UI线程),这可以使用As ...
- Eclipse手动添加web.xml
当创建web工程时,没有自动创建web.xml 这时候就需要手动添加web.xml 该怎么做呢 右键项目,点击java EE Tools 其中点击Genertate Deployment Descri ...
- input只能输入数字字母
<input type='text' onkeyup="this.value=this.value.replace(/[^0-9-]+/,'');" /> 只能输入数字 ...
- 在vue中添加sass的配置的方法
1.安装sass的依赖包 npm install --save-dev sass-loader //sass-loader依赖于 node-sass npm install --save-dev no ...
- CentOS 7系统上添加netcdf库
这里提供两种方法来安装 netcdf: 一是 yum 安装,yum 安装时采用的是系统自带的 gfortran 编译器,版本较旧: 二是采用源码来 Makefile 编译安装的方式,它可以下载最新版的 ...