結果

問題 No.677 10^Nの約数
ユーザー yuppe19 😺yuppe19 😺
提出日時 2018-07-25 21:36:27
言語 Python2
(2.7.18)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 2,106 bytes
コンパイル時間 634 ms
コンパイル使用メモリ 6,768 KB
実行使用メモリ 10,388 KB
最終ジャッジ日時 2023-09-09 10:22:20
合計ジャッジ時間 2,192 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
10,224 KB
testcase_01 AC 24 ms
10,292 KB
testcase_02 AC 25 ms
10,224 KB
testcase_03 AC 25 ms
10,272 KB
testcase_04 AC 24 ms
10,196 KB
testcase_05 AC 24 ms
10,328 KB
testcase_06 AC 25 ms
10,360 KB
testcase_07 AC 25 ms
10,212 KB
testcase_08 AC 25 ms
10,212 KB
testcase_09 AC 25 ms
10,236 KB
testcase_10 AC 25 ms
10,280 KB
testcase_11 AC 25 ms
10,276 KB
testcase_12 AC 25 ms
10,236 KB
testcase_13 AC 25 ms
10,276 KB
testcase_14 AC 26 ms
10,212 KB
testcase_15 AC 26 ms
10,276 KB
testcase_16 AC 26 ms
10,216 KB
testcase_17 AC 26 ms
10,388 KB
testcase_18 AC 25 ms
10,288 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/python2
# -*- coding: utf-8 -*-
# †
from collections import defaultdict, deque
from fractions import gcd
from itertools import product
from operator import mul
from random import randrange

def is_probable_prime(n, k=20):
    if n == 1: return False
    for p in [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]:
        if n == p:     return True
        if n % p == 0: return False
    s, d = 0, n-1
    while d & 1 == 0:
        s, d = s+1, d>>1
    for _ in xrange(k):
        a = randrange(2, n-1)
        x = pow(a, d, n)
        if x == 1 or x == n-1:
            continue
        for _ in xrange(s-1):
            x = (x * x) % n
            if x == n-1:
                break  # could be strong liar, try another a
        else:
            return False  # composite if we reached end of this loop
    return True  # probably prime if reached end of outer loop

def brent(n):
    if not n & 1:
        return 2
    x = randrange(0, n)
    c = randrange(1, n)
    m = randrange(1, n)
    y, r, q = x, 1, 1
    g, ys = 0, 0
    while g <= 1:
        x = y
        for _ in xrange(r):
            y = (y*y + c) % n
        k = 0
        while k < r and g <= 1:
            ys = y
            for _ in xrange(min(m, r-k)):
                y = (y*y + c) % n
                q = (q*abs(x-y)) % n
            g, k = gcd(q, n), k+m
        r <<= 1
    if g == n:
        while g <= 1:
            ys = (ys*ys + c) % n
            g = gcd(abs(x-ys), n)
    return g

def factorize(n):
    que = deque()
    res = defaultdict(int)
    if n == 1:
        return res
    que.append(n)
    while len(que):
        l = que.pop()
        if is_probable_prime(l):
            res[l] += 1
            continue
        d = brent(l)
        que.append(d)
        if d != l:
            que.append(l//d)
    return res

def fast_divisors(n):
    fac = factorize(n)
    res = sorted(set(reduce(mul, [x**y for x, y in zip(fac.keys(), pro)] or [1]) for pro in product(*(xrange(v+1) for v in fac.values()))))
    return res

n = int(raw_input())
divs = fast_divisors(10**n)
res = '\n'.join(map(str, divs))
print res
0