結果

問題 No.300 平方数
ユーザー MJDigit
提出日時 2015-11-21 19:22:31
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
RE  
実行時間 -
コード長 1,072 bytes
コンパイル時間 563 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 11,776 KB
最終ジャッジ日時 2024-09-13 17:07:30
合計ジャッジ時間 3,544 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 RE * 1
other AC * 4 RE * 39
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.py:6: SyntaxWarning: "is" with 'int' literal. Did you mean "=="?
  if n % 2 is 0:
Main.py:13: SyntaxWarning: "is" with 'int' literal. Did you mean "=="?
  while d is 1:
Main.py:13: SyntaxWarning: "is" with 'int' literal. Did you mean "=="?
  while d is 1:
Main.py:34: SyntaxWarning: "is not" with 'int' literal. Did you mean "!="?
  while n is not 1:
Main.py:34: SyntaxWarning: "is not" with 'int' 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