Hdu2503: A/B + C/D

Source: Internet
Author: User
Problem description gives you two scores, asks for their sum, and asks for the sum and the simplest form.

Input first contains a positive integer T (t <= 1000), indicating that there are T groups of test data, followed by T rows of data, each line contains four positive integers a, B, c, D (0 <1000) indicates two scores, A/B and C/D.
 

Output outputs two integers E and F for each group of test data, indicating that the simplest result of A/B + C/D is E/F, and each group of output occupies one row.

Sample Input

2 1 2 1 3 4 3 2 3 Sample output 
5 6 2 1  

 

 

# Includeint Yue (int m, int N) // obtain the maximum approximate number of molecular denominator {int T, R; If (M> N) {T = N; n = m; M = T;} while (m) {r = n % m; n = m; M = r;} return N;} int main () {int T,, b, c, d; int n, m, K; scanf ("% d", & T); While (t --) {scanf ("% d", & A, & B, & C, & D); M = B * D; // Denominator = A * D + B * C; // the numerator after the denominator is added if (M = N) // The condition where the numerator and denominator are the same {printf ("1 1 \ n"); continue;} k = Yue (m, n ); printf ("% d \ n", N/K, M/K); // simplification of molecules and denominator} return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.