#include<iostream>
#define l unsigned long long int
using namespace std;
l anik(int a, int b)
{
l r;
if(a < b)
swap(a, b);
while(b!= 0)
{
r = a%b;
a = b;
b = r;
}
return a;
}
int main()
{
int n, i, j;
l g;
while(cin >> n)
{
if(n == 0)
break;
g = 0;
for(i=1;i<n;i++)
{
for(j=i+1;j<=n;j++)
{
g = g + anik(i, j);
}
}
cout << g << endl;
}
return 0;
}
#define l unsigned long long int
using namespace std;
l anik(int a, int b)
{
l r;
if(a < b)
swap(a, b);
while(b!= 0)
{
r = a%b;
a = b;
b = r;
}
return a;
}
int main()
{
int n, i, j;
l g;
while(cin >> n)
{
if(n == 0)
break;
g = 0;
for(i=1;i<n;i++)
{
for(j=i+1;j<=n;j++)
{
g = g + anik(i, j);
}
}
cout << g << endl;
}
return 0;
}
Comments
Post a Comment