結果
問題 | No.219 巨大数の概算 |
ユーザー |
![]() |
提出日時 | 2025-04-15 22:42:21 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,087 bytes |
コンパイル時間 | 358 ms |
コンパイル使用メモリ | 81,668 KB |
実行使用メモリ | 102,268 KB |
最終ジャッジ日時 | 2025-04-15 22:44:51 |
合計ジャッジ時間 | 5,910 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 5 TLE * 27 -- * 19 |
ソースコード
import sys from decimal import Decimal, getcontext getcontext().prec = 35 # Sufficient precision to handle large exponents def main(): input = sys.stdin.read().split() idx = 0 n = int(input[idx]) idx += 1 results = [] for _ in range(n): a = int(input[idx]) b = int(input[idx+1]) idx += 2 # Compute log10(a) using natural logarithm to avoid domain issues log_a = Decimal(a).ln() / Decimal(10).ln() log_ab = log_a * Decimal(b) # Extract integer part (Z) and fractional part (d) z = int(log_ab) d = log_ab - z # Compute 10^d ten_d = Decimal(10) ** d # Convert to string to extract X and Y s = format(ten_d, '.35f') # Get enough digits to avoid rounding issues if 'e' in s or 'E' in s: # Handle exponential notation if it occurs (unlikely with current settings) ten_d_eng = ten_d.to_eng_string() if 'e' in ten_d_eng: int_part, exp_part = ten_d_eng.split('e') int_part = int_part.replace('.', '') int_part = int_part.lstrip('0') or '0' x = int(int_part[0]) y = 0 else: parts = ten_d_eng.split('.') int_part = parts[0] frac_part = parts[1] if len(parts) > 1 else '' x = int(int_part[0]) y = int(frac_part[0]) if len(frac_part) > 0 else 0 else: parts = s.split('.') int_part = parts[0] frac_part = parts[1] if len(parts) > 1 else '' # Handle leading zeros in integer part (unlikely but possible) int_part = int_part.lstrip('0') or '0' x = int(int_part[0]) if int_part != '0' else 0 # Extract Y from the first digit of fractional part y = int(frac_part[0]) if len(frac_part) > 0 else 0 results.append(f"{x} {y} {z}") print('\n'.join(results)) if __name__ == "__main__": main()