21 December 2017

UVA 11417 python solution

from sys import stdin
scan = lambda : stdin.readline()

def gcd(a,b):
    if b==0:
        return a
    return gcd(b,a%b)


while True:
    num = int(scan())
    if num ==0:
        break    sum=0    for i in range(1,num):
        for j in range(i+1,num+1):
            sum = sum + gcd(i,j)

    print(sum)

No comments:

Post a Comment

UVA 10679 - I Love Strings!!