Skip to content

Instantly share code, notes, and snippets.

@matsubara0507
Created November 6, 2017 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matsubara0507/22458624a1ba737ccbfe7390091eb338 to your computer and use it in GitHub Desktop.
Save matsubara0507/22458624a1ba737ccbfe7390091eb338 to your computer and use it in GitHub Desktop.
1から1000までの整数に対して最小連続平方根を求めそれが10以下であればその数と最小連続平方根を出力するスクリプト
# coding: utf-8
import math
def is_int(n):
return n % 1 == 0
def int_sqrt(n):
a = math.sqrt(n)
if is_int(a):
return int(a)
else:
return 0
def int_sqrt_min(n):
a = int_sqrt(n)
b = a
while a > 1:
b = a
a = int_sqrt(a)
return b
ocm_list = []
ocn_list = []
for x in range(1, 1001):
y = int_sqrt_min(x)
if 0 < y <= 10:
ocm_list.append(x)
ocn_list.append(y)
print (ocm_list)
print (ocn_list)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment