Problem p02713 - Generation 2

Orig Description

Score : 300 points
Problem StatementFind \displaystyle{\sum_{a=1}^{K}\sum_{b=1}^{K}\sum_{c=1}^{K} \gcd(a,b,c)}.
Here \gcd(a,b,c) denotes the greatest common divisor of a, b, and c.
Constraints
1 \leq K \leq 200
K is an integer.
InputInput is given from Standard Input in the following format:
K
OutputPrint the value of \displaystyle{\sum_{a=1}^{K}\sum_{b=1}^{K}\sum_{c=1}^{K} \gcd(a,b,c)}.
Sample Input 12
Sample Output 19
\gcd(1,1,1)+\gcd(1,1,2)+\gcd(1,2,1)+\gcd(1,2,2)
+\gcd(2,1,1)+\gcd(2,1,2)+\gcd(2,2,1)+\gcd(2,2,2)
=1+1+1+1+1+1+1+2=9
Thus, the answer is 9.
Sample Input 2200
Sample Output 210813692

Extracted Specification

An integer K (1 ≤ K ≤ 200).

### Example Input:

```
12
```

### Function Signature:
Write a function f(K) that takes in the input. 
```python
def f(K: int):
    ''' 
    K: an integer
    '''
```

Test Case Generator

Certainly! Below is the test case generator for the given problem statement:

```python
import random

def tcgen():
    # Generate a random integer K such that 1 ≤ K ≤ 200
    K = random.randint(1, 200)
    
    return K

# Example usage
if __name__ == "__main__":
    # Generate a test case
    test_case = tcgen()
    
    # Print the test case in the required format
    print(test_case)
```

This generator produces a random integer \( K \) within the specified range, which is the input for the problem. Each time you run the generator, it will produce a different value of \( K \).

For a complete testing setup, you might also want to include the function to calculate the output based on the generated \( K \). Here is an example implementation for the calculation:

```python
import math

def calculate_gcd_sum(K):
    gcd_sum = 0
    for a in range(1, K + 1):
        for b in range(1, K + 1):
            for c in range(1, K + 1):
                gcd_sum += math.gcd(math.gcd(a, b), c)
    return gcd_sum

# Example usage
if __name__ == "__main__":
    # Generate a test case
    K = tcgen()
    
    # Print the test case in the required format
    print(f"Input: {K}")
    
    # Calculate the output
    result = calculate_gcd_sum(K)
    
    # Print the result
    print(f"Output: {result}")
```

This code will generate a random test case, print it, and then calculate and print the expected output based on the problem's requirements. The `calculate_gcd_sum` function computes the sum of the greatest common divisors for all triplets \((a, b, c)\) where \(1 \leq a, b, c \leq K\).

Extract Arguments

def extract_arguments(fh):
    K = int(fh.readline().strip())
    return (K,)