#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int gcd(int a, int b)
{
if(b==0) return a;
return gcd(b, a%b);
}
int main()
{
int n, i, j;
int G;
while(scanf("%d", &n)==1)
{
if(n==0) break;
G=0;
for(i=1;i<n;i++)
for(j=i+1;j<=n;j++)
{
G+=gcd(i,j);
}
printf("%d\n", G);
}
}
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int gcd(int a, int b)
{
if(b==0) return a;
return gcd(b, a%b);
}
int main()
{
int n, i, j;
int G;
while(scanf("%d", &n)==1)
{
if(n==0) break;
G=0;
for(i=1;i<n;i++)
for(j=i+1;j<=n;j++)
{
G+=gcd(i,j);
}
printf("%d\n", G);
}
}
No comments:
Post a Comment