fork(2) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4.  
  5. int GCD(int i,int j){
  6.  
  7. int m,k=0,a[100];
  8.  
  9. int d=0;
  10.  
  11. for(m=1;m<=i;m++){
  12.  
  13. if(((i%m)==0) && ((j%m)==0)){
  14.  
  15. a[k]=m;
  16.  
  17. if(a[k]>d){
  18.  
  19. d=a[k];
  20.  
  21. }
  22.  
  23. }
  24.  
  25. k++;
  26.  
  27. }
  28.  
  29. return d;
  30.  
  31. }
  32.  
  33.  
  34. int main()
  35. {
  36. int i,j,N,G;
  37.  
  38. while(scanf("%d",&N)==1){
  39.  
  40. G=0;
  41.  
  42. if(N==0){
  43.  
  44. break;
  45.  
  46. }
  47.  
  48. for(i=1;i<N;i++){
  49.  
  50. for(j=i+1;j<=N;j++)
  51.  
  52. {
  53. G+=GCD(i,j);
  54.  
  55. }
  56.  
  57. }
  58.  
  59. printf("%d\n",G);
  60.  
  61. }
  62.  
  63. return 0;
  64. }
  65.  
Success #stdin #stdout 0s 2248KB
stdin
Standard input is empty
stdout
Standard output is empty