UVA 11417

#include<bits/stdc++.h>
using namespace std;

int main()
{
    long long int a,sum=0;
    while(cin>>a){
    if(a==0)
    {
        break;
    }
    else
    {
        for(long long int i=1; i<a; i++)
        {
            for(long long j=i+1; j<=a; j++)
            {
                sum=sum+__gcd(i,j);
            }
        }
        cout<<sum<<endl;
        sum=0;
    }
    }
    return 0;
}

Comments

Popular posts from this blog

C++ STL practice problem link

Binary Index Tree(BIT)

Combinatorics