CF 337B (Routine Problem-formula)

Source: Internet
Author: User

Time limit per test1 second
Memory limit per test256 megabytes
Inputstandard input
Outputstandard output
Manao has a monitor. the screen of the monitor has horizontal to vertical length ratio a: B. now he is going to watch a movie. the movie's frame has horizontal to vertical length ratio c: d. manao adjusts the view in such a way that the movie preserves the original frame ratio, but also occupies as much space on the screen as possible and fits within it completely. thus, he may have to zoom the movie in or out, but Manao will always change the frame proportionally in both dimensions.

Calculate the ratio of empty screen (the part of the screen not occupied by the movie) to the total screen size. Print the answer as an irrecoverable cible fraction p limit/limit q.

Input
A single line contains four space-separated integers a, B, c, d (1 ≤ Clerk a, Clerk B, clerk c, clerk d ≤ clerk 1000 ).

Output
Print the answer to the problem as "p/q", where p is a non-negative integer, q is a positive integer and numbers p and q don't have a common divisor larger than 1.

Sample test (s)
Input
1 1 3 2
Output
1/3
Input
4 3 2 2
Output
1/4
Note
Sample 1. manao's monitor has a square screen. the movie has :2 horizontal to vertical length ratio. obviusly, the movie occupies most of the screen if the width of the picture coincides with the width of the screen. in this case, only 2/3 of the monitor will project the movie in the horizontal dimension:

 

Sample 2. this time the monitor's width is 4/3 times larger than its height and the movie's frame is square. in this case, the picture must take up the whole monitor in the vertical dimension and only 3/4 in the horizontal dimension:

 

 

 


Formula questions ..

 

#include<cstdio>#include<cstring>#include<cstdlib>#include<algorithm>#include<functional>#include<iostream>#include<cmath>#include<cctype>#include<ctime>using namespace std;#define For(i,n) for(int i=1;i<=n;i++)#define Fork(i,k,n) for(int i=k;i<=n;i++)#define Rep(i,n) for(int i=0;i<n;i++)#define ForD(i,n) for(int i=n;i;i--)#define RepD(i,n) for(int i=n;i>=0;i--)#define Forp(x) for(int p=pre[x];p;p=next[p])#define Lson (x<<1)#define Rson ((x<<1)+1)#define MEM(a) memset(a,0,sizeof(a));#define MEMI(a) memset(a,127,sizeof(a));#define MEMi(a) memset(a,128,sizeof(a));#define INF (2139062143)#define F (100000007)long long mul(long long a,long long b){return (a*b)%F;}long long add(long long a,long long b){return (a+b)%F;}long long sub(long long a,long long b){return (a-b+(a-b)/F*F+F)%F;}typedef long long ll;int gcd(int a,int b){if (b==0) return a;return gcd(b,a%b);}int mib(int &a,int &b){int g=gcd(a,b);a/=g,b/=g;}int a,b,c,d;int main(){//freopen(".in","r",stdin);//freopen(".out","w",stdout);cin>>a>>b>>c>>d;mib(a,b),mib(c,d);if ((double)a/b>(double)c/d) swap(a,b),swap(c,d);int p=a*d,q=c*b;mib(p,q);cout<<q-p<<'/'<<q<<endl;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.