QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#676944#5465. Maximum GCDANAS_IIUCWA 7ms10704kbPython3714b2024-10-26 04:15:312024-10-26 04:15:32

Judging History

你现在查看的是最新测评结果

  • [2024-10-26 04:15:32]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:10704kb
  • [2024-10-26 04:15:31]
  • 提交

answer

import math
import sys
input = sys.stdin.read

def max_beautiful_gcd(arr):
    n = len(arr)
    if n == 1:
        return arr[0]  # If there's only one element, its value is the max GCD
    
    # Find the minimum element in the array
    min_elem = min(arr)
    
    # Calculate GCD of all (arr[i] - min_elem)
    gcd_diff = 0
    for num in arr:
        gcd_diff = math.gcd(gcd_diff, num - min_elem)
        if gcd_diff == 1:
            break  # No need to continue if gcd_diff is 1, as it is the smallest possible GCD
    
    return gcd_diff

# Input reading
data = input().split()
n = int(data[0])
arr = list(map(int, data[1:]))

# Output the result
print(max_beautiful_gcd(arr))

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 7ms
memory: 10704kb

input:

3
3 10 7

output:

1

result:

wrong answer 1st numbers differ - expected: '3', found: '1'