Skip to content

Instantly share code, notes, and snippets.

@shohan4556
Created February 4, 2015 19:24
Show Gist options
  • Select an option

  • Save shohan4556/0d7929ce576f3f2900c0 to your computer and use it in GitHub Desktop.

Select an option

Save shohan4556/0d7929ce576f3f2900c0 to your computer and use it in GitHub Desktop.
Uva 11417 solution in C
/// Author : Md.Shohanur Rahaman
/// UVA -- 11417 (GCD)
// Problem Type : Math - Easy
#include<stdio.h>
int gcd(int a,int b);
int main()
{
int i,j,sum=0,n=0;
while(scanf("%d",&n)==1){
if(n==0)
break;
sum=0;
for(i=1;i<n;i++){
for(j=i+1;j<=n;j++){
sum+=gcd(i,j);
}
}
printf("%d\n",sum);
}
return 0;
}
int gcd(int a,int b)
{
if(b==0)
return a;
else
return gcd(b,a%b);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment