結果

問題 No.1143 面積Nの三角形
ユーザー 👑 KazunKazun
提出日時 2021-08-13 17:23:25
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,432 bytes
コンパイル時間 199 ms
コンパイル使用メモリ 82,516 KB
実行使用メモリ 76,924 KB
最終ジャッジ日時 2024-04-14 11:05:02
合計ジャッジ時間 5,866 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,352 KB
testcase_01 AC 49 ms
64,320 KB
testcase_02 AC 50 ms
64,648 KB
testcase_03 AC 52 ms
64,160 KB
testcase_04 AC 50 ms
63,620 KB
testcase_05 AC 56 ms
66,708 KB
testcase_06 AC 56 ms
65,984 KB
testcase_07 AC 106 ms
76,304 KB
testcase_08 AC 179 ms
76,876 KB
testcase_09 AC 167 ms
76,768 KB
testcase_10 AC 140 ms
76,764 KB
testcase_11 AC 303 ms
76,872 KB
testcase_12 AC 329 ms
76,736 KB
testcase_13 AC 332 ms
76,644 KB
testcase_14 AC 121 ms
71,956 KB
testcase_15 AC 37 ms
52,656 KB
testcase_16 AC 636 ms
76,588 KB
testcase_17 AC 672 ms
76,764 KB
testcase_18 TLE -
testcase_19 AC 502 ms
76,924 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def Divisors(N):
    N=abs(N)
    L,U=[],[]
    k=1
    while k*k <=N:
        if N%k== 0:
            L.append(k)
            if k*k!=N:
                U.append(N//k)
        k+=1
    return L+U[::-1]

def Floor_Root(a,k):
    """floor(a^(1/k)) を求める.

    a:非負整数
    k:正の整数
    """
    assert 0<=a and 0<k
    if a==0: return 0
    if k==1: return a

    #大体の値を求める.
    x=int(pow(a,1/k))

    #増やす
    while pow(x+1,k)<=a:
        x+=1

    #減らす
    while pow(x,k)>a:
        x-=1
    return x
#==================================================
def f(c,x):
    if S%(c*c-x*x)==0:
        M=S//(c*c-x*x)+c*c
        if M>=0:
            L=Floor_Root(M,2)
            if L*L==M:
                return L
            else:
                return -1
        else:
            return -1
    else:
        return -1

def sq_area(a,b,c):
    s=(a+b+c)//2
    return 16*s*(s-a)*(s-b)*(s-c)

def is_valid(a,b,c):
    return min(a,b,c)>=1 and sq_area(a,b,c)==S and abs(b-c)<a<b+c

N=int(input())
S=16*N*N

D=Divisors(S); M=len(D)
E=set()

for i in range(M):
    p=D[i]
    for j in range(i+1):
        q=D[j]

        if (p+q)%2==1:
            continue

        x=(-p+q)//2; c=(p+q)//2
        y=f(c,x)

        if y>=0:
            a=( x+y)//2
            b=(-x+y)//2

            if is_valid(a,b,c):
                a,b,c=sorted([a,b,c])
                E.add((a,b,c))

print(len(E))
0