Source Code
#include<iostream>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<climits>
long gcd(long n,long m)
{
	while(n!=m)
	{
		if(n>m)
			n-=m;
		else
			m-=n;
	}
	return n;
}
using namespace std;
int main() {
long a,b,r,l,rr,ll;
cin>>a>>b>>r>>l>>rr>>ll;
long m=gcd(a,b);
a=a/m;
b=b/m;
for(int i=r;i<=l;i++)
{
	if(i%a==0)
	{
		long k=i/a*b;
		if(k>=rr&&k<=ll)
		{
			cout<<i<<" "<<k;
			return 0;
		}

	}
}
if(b>a)
cout<<r<<" "<<ll;
else
cout<<l<<" "<<rr;
	return 0;
}
Copy
Fractions sameh58
GNU G++17
1 ms
620 KB
Wrong Answer