結果
| 問題 | 
                            No.211 素数サイコロと合成数サイコロ (1)
                             | 
                    
| コンテスト | |
| ユーザー | 
                             qwewe
                         | 
                    
| 提出日時 | 2025-05-14 12:59:48 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 41 ms / 1,000 ms | 
| コード長 | 2,610 bytes | 
| コンパイル時間 | 215 ms | 
| コンパイル使用メモリ | 82,604 KB | 
| 実行使用メモリ | 53,996 KB | 
| 最終ジャッジ日時 | 2025-05-14 13:00:56 | 
| 合計ジャッジ時間 | 2,324 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 33 | 
ソースコード
# -*- coding: utf-8 -*-
import sys
# Function to read a single integer from standard input
def get_int():
    """Reads a line from stdin, removes leading/trailing whitespace, and converts it to an integer."""
    return int(sys.stdin.readline().strip())
# Main function containing the problem-solving logic
def solve():
    """Solves the Prime and Composite Dice problem."""
    
    # Read the target product K from input
    k = get_int()
    # Define the faces of the prime die (素数サイコロ)
    # These are the first 6 prime numbers.
    prime_faces = [2, 3, 5, 7, 11, 13]
    
    # Define the faces of the composite die (合成数サイコロ)
    # These are the first 6 composite numbers greater than 1.
    composite_faces = [4, 6, 8, 9, 10, 12]
    # Initialize a counter for outcomes where the product of the faces equals K
    favorable_outcomes_count = 0
    
    # Calculate the total number of possible outcomes when rolling both dice.
    # Each die has 6 faces, and the rolls are independent.
    # The total number of possible pairs (prime_face, composite_face) is 6 * 6 = 36.
    total_outcomes = len(prime_faces) * len(composite_faces) # This will be 36
    # Iterate through each possible face value of the prime die
    for p_face in prime_faces:
        # For each prime face value, iterate through each possible face value of the composite die
        for c_face in composite_faces:
            # Check if the product of the current pair of face values equals the target K
            if p_face * c_face == k:
                # If the product matches K, increment the count of favorable outcomes
                favorable_outcomes_count += 1
    # Calculate the probability.
    # Probability = (Number of favorable outcomes) / (Total number of outcomes)
    # Use float() conversion for total_outcomes to ensure floating-point division, 
    # which is necessary for calculating the probability accurately.
    # Since total_outcomes is guaranteed to be 36 (non-zero), we don't need to check for division by zero.
    probability = favorable_outcomes_count / float(total_outcomes)
    # Print the calculated probability.
    # The problem requires the output to be accurate up to an absolute error of 10^-12.
    # Formatting the output to 17 decimal places using an f-string is a standard way 
    # to ensure sufficient precision for competitive programming tasks.
    print(f"{probability:.17f}")
# Standard Python entry point check. 
# This ensures that the solve() function is called only when the script is executed directly.
if __name__ == '__main__':
    solve()
            
            
            
        
            
qwewe