The third set of questions in North Qing Dynasty

Source: Internet
Author: User

Paving Tiles
"Problem description"
There is a long, long wall. You need to put two lines of tiles on this wall. You have two different sizes of tiles on hand, and you want to put one line on each of these two tiles. The length of the tile can be expressed in fractions, each tile of the first line is AB, and the length of each tile affixed to the second row is CD. You don't need to care about the width of the tile in this question.
As shown, the two rows of tiles start right from the same starting position, and the gap on the left side of the first block of two rows of tiles is aligned. You want to know, the shortest distance, the gap between the two rows of tiles will be again aligned.
The 1th line of the input contains a positive integer T, which represents the number of groups of test data.
Next T line, 4 positive integers per line a,b,c,d, indicates that the two tiles in the group test data are of the length AB and CD respectively.
The output contains a T-line, and the line I contains a fraction or integer that represents the answer to the group I data. If the answer is a score, it is output in the format "x/y" without quotation marks. Fractions must be reduced to a minimalist form. If the answer is an integer, an integer X is output.
"Input and output Example 1" tile.out
1 2 1 3
1 2 5 6
See Tile/ and Tile/tile1.out under the catalogue of contestants
"Input and output Example 1 description"
For the first set of data, the first row of tiles affixed 2 blocks, the second line affixed 3 pieces, the total length is 1, that is, the distance from the beginning of the position of 1, the gap between the two lines of tiles will be aligned again.
For the second set of data, the first line tiles 5 blocks, the second line is affixed with 3 pieces, the total length is 52.
"Input and output Example 2"
See Tile/ and Tile/tile2.out under the catalogue of contestants
"Data size and conventions"
For 50% of data, 1≤a,b,c,d≤20
For 70% of data, t≤10
For 100% of data, t≤100,000,1≤a,b,c,d≤10,000

Solution: The least common multiple of the two denominator is the answer. Water.

#include <cstdio>#include<iostream>#include<algorithm>#definell Long Longusing namespacestd;intt;ll FZ1,FZ2,FM;intA,b,c,d;ll GCD1 (ll x, ll y)//Max Common factor{    if(y==0)returnx; ll K=x%y; GCD1 (y,k);}intMain () {Freopen ("","R", stdin); Freopen ("Tile.out","W", stdout); scanf ("%d",&T);  while(t--) {scanf ("%d%d%d%d",&a,&b,&c,&d); ll K1=GCD1 (b,d); FM=b/k1*k1* (D/K1);//-Passfz1=fm/b*A; FZ2=fm/d*C; K1=GCD1 (FZ1,FZ2); ll FZ=k1* (FZ1/K1) * (FZ2/K1);//To the simplest integer ratio            if(fz%fm==0) cout<<fz/fm<<Endl; Else{K1=GCD1 (FZ,FM); FZ/=k1;fm/=K1; cout<<fz<<'/'<<fm<<Endl;    }} fclose (stdin);        Fclose (stdout); return 0;}
Beg least common multiple

The third set of questions in North Qing Dynasty

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: 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.