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), representing some quantity or size.
### Example Input:
```
12
```
### Function Signature:
Write a function f(K) that takes in the input.
def f(K: int):
'''
K: an integer
'''
Test Case Generator
Certainly! Below is a test case generator for the given competitive programming problem:
```python
import random
def tcgen():
K = random.randint(1, 200)
return K,
# Example usage:
for _ in range(5): # generate 5 test cases
print(tcgen())
```
This function generates a random integer \( K \) within the specified constraints (1 ≤ K ≤ 200). The output is a tuple containing \( K \), which is suitable for the format expected by competitive programming platforms.
If you want to also generate the expected output for these test cases, you would need to implement the logic to compute the sum of the greatest common divisors as described in the problem statement. Here’s an implementation to compute the expected output:
```python
import math
def compute_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
def tcgen_with_output():
K = random.randint(1, 200)
expected_output = compute_gcd_sum(K)
return (K,), expected_output
# Example usage:
for _ in range(5): # generate 5 test cases with expected outputs
test_case, expected_output = tcgen_with_output()
print(f"Input: {test_case}, Output: {expected_output}")
```
This extended version of the test case generator not only creates the input \( K \) but also computes the correct output for the given \( K \) using the `compute_gcd_sum` function. This can be useful for validating your solution or for creating comprehensive test cases for practice.