結果

問題 No.300 平方数
ユーザー 🍡yurahuna🍡yurahuna
提出日時 2015-12-21 21:57:18
言語 Python2
(2.7.18)
結果
AC  
実行時間 102 ms / 1,000 ms
コード長 1,040 bytes
コンパイル時間 505 ms
コンパイル使用メモリ 7,132 KB
実行使用メモリ 6,744 KB
最終ジャッジ日時 2023-10-18 22:07:14
合計ジャッジ時間 4,394 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
6,684 KB
testcase_01 AC 18 ms
6,744 KB
testcase_02 AC 72 ms
6,744 KB
testcase_03 AC 12 ms
6,500 KB
testcase_04 AC 12 ms
6,744 KB
testcase_05 AC 12 ms
6,744 KB
testcase_06 AC 12 ms
6,744 KB
testcase_07 AC 11 ms
6,744 KB
testcase_08 AC 12 ms
6,684 KB
testcase_09 AC 12 ms
6,744 KB
testcase_10 AC 12 ms
6,744 KB
testcase_11 AC 12 ms
6,744 KB
testcase_12 AC 13 ms
6,744 KB
testcase_13 AC 101 ms
6,744 KB
testcase_14 AC 20 ms
6,744 KB
testcase_15 AC 57 ms
6,684 KB
testcase_16 AC 53 ms
6,744 KB
testcase_17 AC 101 ms
6,684 KB
testcase_18 AC 19 ms
6,744 KB
testcase_19 AC 45 ms
6,744 KB
testcase_20 AC 31 ms
6,744 KB
testcase_21 AC 102 ms
6,744 KB
testcase_22 AC 91 ms
6,744 KB
testcase_23 AC 86 ms
6,744 KB
testcase_24 AC 63 ms
6,744 KB
testcase_25 AC 85 ms
6,744 KB
testcase_26 AC 78 ms
6,744 KB
testcase_27 AC 57 ms
6,744 KB
testcase_28 AC 83 ms
6,744 KB
testcase_29 AC 93 ms
6,744 KB
testcase_30 AC 95 ms
6,744 KB
testcase_31 AC 98 ms
6,744 KB
testcase_32 AC 64 ms
6,744 KB
testcase_33 AC 42 ms
6,744 KB
testcase_34 AC 92 ms
6,744 KB
testcase_35 AC 65 ms
6,744 KB
testcase_36 AC 73 ms
6,744 KB
testcase_37 AC 62 ms
6,744 KB
testcase_38 AC 72 ms
6,744 KB
testcase_39 AC 79 ms
6,744 KB
testcase_40 AC 70 ms
6,744 KB
testcase_41 AC 39 ms
6,744 KB
testcase_42 AC 64 ms
6,744 KB
testcase_43 AC 92 ms
6,744 KB
testcase_44 AC 75 ms
6,744 KB
testcase_45 AC 44 ms
6,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#入力Xに対し、X*Yが平方数となるような最小のYを求める
#Yは、 Xを素因数分解したとき、指数が奇数である数の積

#素因数分解
#引数: 整数n
#返り値: 素因数分解の結果table[]
#tabelは[2, 2, 2, 3, 5, 5,...]のようになる
def prime_decomposition(n):
    i = 2
    table = []
    SQRT_N = int(n**0.5)
    while i <= SQRT_N:
        while n % i == 0:
            n /= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table

def main():
    x = input()
    table = prime_decomposition(x)
    if table == []:
        print 1
    else:
        done = []
        divisor_y = []
        for i in xrange(len(table)):
            if not table[i] in done:
                if table.count(table[i]) % 2 != 0:
                    divisor_y.append(table[i])
            done.append(table[i])
        if divisor_y == []:
            print 1
        else:
            print reduce(lambda x, y:x*y, divisor_y)
    
if __name__ == "__main__":
    main()
0