結果

問題 No.414 衝動
ユーザー nohakai3nohakai3
提出日時 2022-11-03 10:48:11
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 123 ms / 1,000 ms
コード長 1,130 bytes
コンパイル時間 572 ms
コンパイル使用メモリ 87,052 KB
実行使用メモリ 76,308 KB
最終ジャッジ日時 2023-09-24 20:25:19
合計ジャッジ時間 3,239 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
76,236 KB
testcase_01 AC 89 ms
72,204 KB
testcase_02 AC 87 ms
72,144 KB
testcase_03 AC 121 ms
76,308 KB
testcase_04 AC 121 ms
76,088 KB
testcase_05 AC 88 ms
72,144 KB
testcase_06 AC 89 ms
72,028 KB
testcase_07 AC 90 ms
71,912 KB
testcase_08 AC 90 ms
72,120 KB
testcase_09 AC 123 ms
76,028 KB
testcase_10 AC 89 ms
71,720 KB
testcase_11 AC 94 ms
75,968 KB
testcase_12 AC 94 ms
76,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import random

def is_prime3(q,k=50):
    q = abs(q)
    #計算するまでもなく判定できるものははじく
    if q == 2: return True
    if q < 2 or q&1 == 0: return False

    #n-1=2^s*dとし(但しaは整数、dは奇数)、dを求める
    d = (q-1)>>1
    while d&1 == 0:
        d >>= 1
    
    #判定をk回繰り返す
    for i in range(k):
        a = random.randint(1,q-1)
        t = d
        y = pow(a,t,q)
        #[0,s-1]の範囲すべてをチェック
        while t != q-1 and y != 1 and y != q-1: 
            y = pow(y,2,q)
            t <<= 1
        if y != q-1 and t&1 == 0:
            return False
    return True
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
n=int(input())
if is_prime3(n)==True:
    print(1,n)
else:
    print(factorization(n)[0][0],n//factorization(n)[0][0])
0