結果

問題 No.1472 作為の和
ユーザー lam6er
提出日時 2025-04-15 21:12:38
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,265 bytes
コンパイル時間 411 ms
コンパイル使用メモリ 82,060 KB
実行使用メモリ 70,820 KB
最終ジャッジ日時 2025-04-15 21:18:39
合計ジャッジ時間 1,425 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 1 WA * 3 RE * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

pi_digits = "31415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989"

def compute_B_max(N):
    if N == 0:
        return 3
    s = pi_digits[:N+1]
    return int(s)

def get_max_m(B_max):
    max_m = 0
    for m in range(0, 1000):  # Sufficiently large upper bound for m
        current = 10 ** m + 1
        if current > B_max:
            break
        max_m = m
    return max_m

def get_factors(n):
    if n == 0:
        return []
    factors = set()
    for i in range(1, int(n**0.5) + 1):
        if n % i == 0:
            factors.add(i)
            factors.add(n // i)
    return sorted(factors)

def solve(N):
    B_max = compute_B_max(N)
    m = get_max_m(B_max)
    
    valid = False
    if m >= 1:
        if 10 ** m + 1 <= B_max:
            valid = True
    
    if valid:
        ten_m = 10 ** m
        ten_m_plus_1 = ten_m + 1
        ten_m_minus_1 = ten_m - 1
        factors = get_factors(ten_m_minus_1)
        count = 0
        for d in factors:
            if d * ten_m_plus_1 <= B_max:
                count += 1
        if count > 0:
            sum_s = 9 * (2 * m)
            return f"{sum_s} {count}"
    
    # Fallback to B_max^2
    product = B_max * B_max
    sum_s = sum(int(c) for c in str(product))
    return f"{sum_s} 1"

N = int(sys.stdin.readline())
print(solve(N))
0