Advertisement
sm2345

47

Jan 12th, 2013
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<iostream>
  2. #include<stdio.h>
  3. #include<math.h>
  4. using namespace std;
  5.  
  6. unsigned long long int gcd(unsigned long long int a, unsigned long long int b)
  7. {
  8.      unsigned long long int c;
  9.      while ( b != 0 )
  10.         {
  11.             c = b;
  12.             b = a % b;
  13.             a = c;
  14.         }
  15.  
  16.         return a;
  17. }
  18.  
  19. struct fraction
  20. {
  21.        unsigned long long int num,denom;
  22. };
  23.  
  24. void reducelowest(struct fraction& a)
  25. {
  26.      unsigned long long int m;
  27.      m=gcd(a.num,a.denom);
  28.      /*unsigned long long int i;
  29.      if(a.num>a.denom)
  30.          m=a.denom;
  31.      else
  32.          m=a.num;
  33.  
  34.      for(i=m;i>=1;i--)
  35.      {
  36.          if(a.num%i==0&&a.denom%i==0)
  37.              break;
  38.       }*/
  39.      a.num=a.num/m;
  40.      a.denom=a.denom/m;
  41.  }
  42.  
  43. int main()
  44. {
  45.     FILE*fp=fopen("omoout.txt","w");
  46.     struct fraction f[104][104];
  47.     for(int i=1;i<=51;i++)
  48.     {
  49.             f[1][i].num=1; f[1][i].denom=i;
  50.             f[i][1]=f[1][i];
  51.             f[2][i].num=(2*i*i*i-2*i+3); f[2][i].denom=6*i;
  52.             reducelowest(f[2][i]);
  53.             f[i][2].num=f[2][i].num;f[i][2].denom=f[2][i].denom;
  54.  
  55.      }
  56.    
  57.  
  58.     for(int i=3;i<=50;i++)
  59.     {
  60.             for(int j=2;j<=49;j++)
  61.             {
  62.                     if(f[i][j+1].denom==0)
  63.                     {
  64.                       f[i][j+1].num=((f[i-1][j].denom)*((f[i-1][j+1].denom)*(f[i][j].denom)+(f[i-1][j+1].num)*(f[i][j].num)));
  65.                       f[i][j+1].denom=(f[i-1][j].num)*(f[i-1][j+1].denom)*(f[i][j].denom);
  66.                       reducelowest(f[i][j+1]);
  67.                     }
  68.             }
  69.      }
  70.     for(int i=1;i<=50;i++)
  71.     {
  72.             //for(int j=1;j<=50;j++)
  73.             //{
  74.                     fprintf(fp,"f(%d,%d)=%lld/%lld    %f\n",i,i,f[i][i].num,f[i][i].denom,pow((f[i][i].num-1),0.5));
  75.             //}
  76.      }
  77.      fclose(fp);
  78.    
  79.      return 0;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement