#include<bits/stdc++.h>
using namespace std;
int gcd(int x, int y);
int main()
{
int G=0 , N;
while(cin>>N){
if(N==0)
break;
for(int i=1; i<N; i++){
for(int j=i+1; j<=N; j++)
G+=gcd(i,j);
}
cout<<G<<endl;
G=0;
}
return 0;
}
int gcd(int x , int y)
{
int gcd=0;
while(x!=y){
if(x>y)
x-=y;
else
y-=x;
}
gcd=x;
return gcd;
}
using namespace std;
int gcd(int x, int y);
int main()
{
int G=0 , N;
while(cin>>N){
if(N==0)
break;
for(int i=1; i<N; i++){
for(int j=i+1; j<=N; j++)
G+=gcd(i,j);
}
cout<<G<<endl;
G=0;
}
return 0;
}
int gcd(int x , int y)
{
int gcd=0;
while(x!=y){
if(x>y)
x-=y;
else
y-=x;
}
gcd=x;
return gcd;
}
No comments:
Post a Comment