結果

問題 No.300 平方数
ユーザー MJDigitMJDigit
提出日時 2015-11-21 19:22:31
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 1,072 bytes
コンパイル時間 354 ms
コンパイル使用メモリ 10,948 KB
実行使用メモリ 9,996 KB
最終ジャッジ日時 2023-10-11 18:11:10
合計ジャッジ時間 3,493 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
9,712 KB
testcase_01 AC 30 ms
9,816 KB
testcase_02 RE -
testcase_03 AC 30 ms
9,676 KB
testcase_04 AC 29 ms
9,696 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 AC 29 ms
9,704 KB
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 AC 29 ms
9,920 KB
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.py:6: SyntaxWarning: "is" with a literal. Did you mean "=="?
  if n % 2 is 0:
Main.py:13: SyntaxWarning: "is" with a literal. Did you mean "=="?
  while d is 1:
Main.py:13: SyntaxWarning: "is" with a literal. Did you mean "=="?
  while d is 1:
Main.py:34: SyntaxWarning: "is not" with a literal. Did you mean "!="?
  while n is not 1:
Main.py:34: SyntaxWarning: "is not" with a literal. Did you mean "!="?
  while n is not 1:

ソースコード

diff #

# -*- coding: utf-8 -*-

import fractions

def factor(n, rho):
    if n % 2 is 0:
        return 2

    f=lambda a:(a*a+rho)%n
    x=2
    y=2
    d=1
    while d is 1:
        x=f(x)
        y=f(f(y))
        d=fractions.gcd(abs(x-y), n)
        #print("n=%d rho=%d: x=%d y=%d d=%d"%(n,rho,x,y,d))
    return d

def add_factor(n, lst):
    for rho in range(2):
        d=factor(n,rho)
        if d is not n:
            break

    lst.append(d)
    return int(n/d), lst

def factorint(n):
    """
    Using Prllard's rho algorithm with Linier congruential generators.
    """
    lst=[]
    while n is not 1:
        n, lst = add_factor(n, lst)
    return lst

def main():
    X=int(input())
    factors=factorint(X)
    factors.sort()

    Y=1
    prev=1
    for index in range(len(factors)):
        # print("%d, %d"%(prev, factors[index]))
        if factors[index] == prev:
            prev=1
        else:
            Y=Y*prev
            # print("  *%d=%d"%(prev, Y))
            prev=factors[index]
    Y=Y*prev
    print(Y)

if __name__ == '__main__':
    main()
0