結果
問題 | No.1143 面積Nの三角形 |
ユーザー |
![]() |
提出日時 | 2025-03-31 17:35:04 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 72 ms / 800 ms |
コード長 | 2,063 bytes |
コンパイル時間 | 216 ms |
コンパイル使用メモリ | 82,256 KB |
実行使用メモリ | 76,652 KB |
最終ジャッジ日時 | 2025-03-31 17:36:12 |
合計ジャッジ時間 | 2,073 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 18 |
ソースコード
import mathdef factorize(n):factors = {}while n % 2 == 0:factors[2] = factors.get(2, 0) + 1n //= 2i = 3while i * i <= n:while n % i == 0:factors[i] = factors.get(i, 0) + 1n //= ii += 2if n > 1:factors[n] = 1return factorsdef generate_divisors(factors):divisors = [1]for p in factors:exp = factors[p]new_divisors = []current_power = 1for _ in range(exp + 1):for d in divisors:new_divisors.append(d * current_power)current_power *= pdivisors = list(set(new_divisors)) # Remove duplicatesdivisors.sort()return divisorsdef main():N = int(input().strip())if N == 0:print(0)returnK = N * Nfactors_n = factorize(N)# Prepare factors for N^2 (each exponent doubled)factors_k = {}for p in factors_n:factors_k[p] = factors_n[p] * 2divisors = generate_divisors(factors_k)count = 0for z in divisors:if z == 0:continueif K % z != 0:continue # Ensure divisibility, though should always be trueKz = K // zif Kz == 0:continuemax_y = int(Kz ** (1/3)) + 2 # Estimate the cube root and add buffermax_y = min(max_y, Kz) # Ensure y doesn't exceed Kzy_start = zy_end = max_yfor y in range(y_start, y_end + 1):if y == 0:continueif Kz % y != 0:continueq = Kz // ysum_yz = y + zD = sum_yz ** 2 + 4 * qs = math.isqrt(D)if s * s != D:continuenumerator = (-sum_yz + s)if numerator <= 0:continueif numerator % 2 != 0:continuex = numerator // 2if x >= y:count += 1print(count)if __name__ == "__main__":main()