Created
November 6, 2017 13:53
-
-
Save matsubara0507/22458624a1ba737ccbfe7390091eb338 to your computer and use it in GitHub Desktop.
1から1000までの整数に対して最小連続平方根を求めそれが10以下であればその数と最小連続平方根を出力するスクリプト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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