結果

問題 No.219 巨大数の概算
ユーザー lam6er
提出日時 2025-04-15 22:40:50
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,096 bytes
コンパイル時間 302 ms
コンパイル使用メモリ 82,072 KB
実行使用メモリ 108,140 KB
最終ジャッジ日時 2025-04-15 22:42:06
合計ジャッジ時間 5,944 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 1
other TLE * 1 -- * 50
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from decimal import Decimal, getcontext, ROUND_FLOOR

def main():
    input = sys.stdin.read().split()
    idx = 0
    N = int(input[idx])
    idx += 1
    
    # Set high precision to handle large exponents accurately
    getcontext().prec = 35
    getcontext().rounding = ROUND_FLOOR
    
    results = []
    for _ in range(N):
        A = int(input[idx])
        B = int(input[idx + 1])
        idx += 2
        
        a = Decimal(A)
        log10_a = a.ln() / Decimal(10).ln()
        log_val = log10_a * Decimal(B)
        
        # Compute k and fractional part f
        k = log_val.to_integral()
        f = log_val - k
        
        # Calculate leading = 10^f
        leading = Decimal(10) ** f
        
        # Determine X and Y
        X = leading.to_integral()
        shifted = leading * Decimal(10)
        shifted_floor = shifted.to_integral()
        Y = shifted_floor % 10
        
        # Convert k to integer for Z
        Z = int(k)
        
        results.append(f"{X} {Y} {Z}")
    
    print('\n'.join(results))

if __name__ == "__main__":
    main()
0