Skip to content

Instantly share code, notes, and snippets.

@seven0525
Last active May 29, 2018 07:51
Show Gist options
  • Save seven0525/380252a7553b5f6cc5d108fdc20a441c to your computer and use it in GitHub Desktop.
Save seven0525/380252a7553b5f6cc5d108fdc20a441c to your computer and use it in GitHub Desktop.
「自作Python100本ノック」1日目(はじめに〜5本目) ref: https://qiita.com/ahpjop/items/373f807d68044cda1c9b
s = 0
for i in range(1,51):
s += i
print(s)
for i in range(2,1001):
for n in range(2,i): #2からその数より以前の数で割り切れないものが素数となる
if i%n == 0:
break
else:
print(i)
a = 0
b = 1
for i in range(10):
print(b)
a, b = b, a+b
#最大公約数
def gcd(a,b):
if b == 0:
return a
else:
return gcd(b,a%b) #この方法で最大公約数が求められます。
a = 16
b = 6
xab = gcd(a,b)
print(xab)
#最小公倍数
zab = a*b/xab #この方法で最小公倍数が求められます。
print(zab)
#最大公約数
for i in range(0,101):
if "3" in str(i) or 0 == i % 3:
print(i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment