fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <assert.h>
  4.  
  5. long long gcd(long long m, long long n)
  6. {
  7. while(m && n) if (m < n) n %= m; else m %= n;
  8. return m + n;
  9. }
  10.  
  11. int main ()
  12. {
  13. int num;
  14. long long n, d, s, p;
  15. scanf("%d", &num);
  16. scanf("%lld/%lld",&s,&p);
  17. assert(p != 0);
  18.  
  19. for (int i = 1; i < num; i++)
  20. {
  21. scanf("%lld/%lld", &n, &d);
  22. assert(d != 0);
  23. s = s*d + n*p;
  24. p *= d;
  25. long long g = gcd(s,p);
  26. s /= g;
  27. p /= g;
  28. }
  29. printf ("%lld/%lld\n", s, p);
  30. }
  31.  
  32.  
Success #stdin #stdout 0s 4716KB
stdin
5
1/145 3/812 1765/2 34442/14334 535/35562
stdout
152618269468807/172463964540