結果

問題 No.1143 面積Nの三角形
ユーザー mkawa2mkawa2
提出日時 2021-06-04 15:20:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 281 ms / 800 ms
コード長 1,680 bytes
コンパイル時間 362 ms
コンパイル使用メモリ 82,240 KB
実行使用メモリ 76,864 KB
最終ジャッジ日時 2024-11-19 00:20:55
合計ジャッジ時間 3,771 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.buffer.readline())
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def LI1(): return list(map(int1, sys.stdin.buffer.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def BI(): return sys.stdin.buffer.readline().rstrip()
def SI(): return sys.stdin.buffer.readline().rstrip().decode()
dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = 10**16
# md = 998244353
# md = 10**9+7

def pf(a):
    pp, ee = [], []
    for p in range(2, a+1):
        if p**2 > a: break
        e = 0
        while a%p == 0:
            a //= p
            e += 1
        if e:
            pp.append(p)
            ee.append(e)
    if a > 1:
        pp.append(a)
        ee.append(1)
    return pp, ee

n = II()
pp, ee = pf(n)
dd = [1]
for p, e in zip(pp, ee):
    s = p
    nd = []
    for _ in range(e*2):
        for d in dd:
            nd.append(d*s)
        s *= p
    dd += nd
dd.sort()
# print(len(dd),dd)

def floor_sqrt(x):
    # print(x)
    a = round(x**0.5-0.45)+1
    while a**2 > x: a -= 1
    return a

n2 = n**2
ans = 0
for i, x in enumerate(dd):
    for y in dd[:i+1]:
        if x*y >= n2: break
        if n2//x%y: continue
        b = x+y
        c = -n2//x//y
        r = floor_sqrt(b**2-4*c)
        if r**2 != b**2-4*c: continue
        z = -b+r
        if z <= 0 or z > y*2 or z & 1: continue
        # print(x,y,z//2)
        ans += 1
print(ans)
0