output
stringlengths 52
181k
| instruction
stringlengths 296
182k
|
---|---|
#include <bits/stdc++.h>
using namespace std;
long long GCD(long long a, long long b) {
if (a % b == 0)
return b;
else
return GCD(b, a % b);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
long long a, b, x, y;
cin >> a >> b >> x >> y;
long long uhu = GCD(x, y);
x = x / uhu, y = y / uhu;
long long bhag1 = a / x, bhag2 = b / y;
long long mini = min(bhag1, bhag2);
cout << mini << endl;
return 0;
}
| ### Prompt
Construct a Cpp code solution to the problem outlined:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long GCD(long long a, long long b) {
if (a % b == 0)
return b;
else
return GCD(b, a % b);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
long long a, b, x, y;
cin >> a >> b >> x >> y;
long long uhu = GCD(x, y);
x = x / uhu, y = y / uhu;
long long bhag1 = a / x, bhag2 = b / y;
long long mini = min(bhag1, bhag2);
cout << mini << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
ifstream in;
ofstream out;
const long long kk = 1000;
const long long MOD = 10e9 + 7;
long long a, b, x, y;
long long GCD(long long n, unsigned long long m) {
while (n != 0 && m != 0) {
if (n > m) {
n %= m;
} else {
m %= n;
}
}
return (n + m);
}
int main() {
ios_base::sync_with_stdio(0);
cin >> a >> b >> x >> y;
long long x1, y1;
long long k = GCD(x, y);
x /= k;
y /= k;
cout << min(a / x, b / y);
return 0;
}
| ### Prompt
In CPP, your task is to solve the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
ifstream in;
ofstream out;
const long long kk = 1000;
const long long MOD = 10e9 + 7;
long long a, b, x, y;
long long GCD(long long n, unsigned long long m) {
while (n != 0 && m != 0) {
if (n > m) {
n %= m;
} else {
m %= n;
}
}
return (n + m);
}
int main() {
ios_base::sync_with_stdio(0);
cin >> a >> b >> x >> y;
long long x1, y1;
long long k = GCD(x, y);
x /= k;
y /= k;
cout << min(a / x, b / y);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b);
int main() {
long long int x, y, a, b, c;
cin >> x >> y >> a >> b;
c = gcd(a, b);
c = (x / (a / c) < y / (b / c)) ? x / (a / c) : y / (b / c);
cout << c;
return 0;
}
long long int gcd(long long int a, long long int b) {
return b ? gcd(b, a % b) : a;
}
| ### Prompt
Your challenge is to write a cpp solution to the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b);
int main() {
long long int x, y, a, b, c;
cin >> x >> y >> a >> b;
c = gcd(a, b);
c = (x / (a / c) < y / (b / c)) ? x / (a / c) : y / (b / c);
cout << c;
return 0;
}
long long int gcd(long long int a, long long int b) {
return b ? gcd(b, a % b) : a;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main() {
long long a, b, x, y, m;
cin >> a >> b >> x >> y;
m = gcd(x, y);
x = x / m;
y = y / m;
cout << min(a / x, b / y);
}
| ### Prompt
Please create a solution in Cpp to the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main() {
long long a, b, x, y, m;
cin >> a >> b >> x >> y;
m = gcd(x, y);
x = x / m;
y = y / m;
cout << min(a / x, b / y);
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main() {
long long a, b, x, y, i, z = 999999, c, d, e;
cin >> a >> b >> x >> y;
z = gcd(x, y);
x /= z;
y /= z;
long long ans = min(a / x, b / y);
cout << ans << endl;
return 0;
}
| ### Prompt
Construct a cpp code solution to the problem outlined:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main() {
long long a, b, x, y, i, z = 999999, c, d, e;
cin >> a >> b >> x >> y;
z = gcd(x, y);
x /= z;
y /= z;
long long ans = min(a / x, b / y);
cout << ans << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
long long a, b, x, y;
cin >> a >> b >> x >> y;
long long g = gcd(x, y);
x /= g, y /= g;
long long t = min(a / x, b / y);
cout << t << endl;
}
| ### Prompt
Your task is to create a cpp solution to the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
long long a, b, x, y;
cin >> a >> b >> x >> y;
long long g = gcd(x, y);
x /= g, y /= g;
long long t = min(a / x, b / y);
cout << t << endl;
}
``` |
#include <bits/stdc++.h>
long long int Foo(long long int a, long long int b);
int main() {
long long int a, b, x, y, i, m, n, p;
while (scanf("%lld%lld%lld%lld,", &a, &b, &x, &y) == 4) {
p = Foo(x, y);
x /= p;
y /= p;
m = a / x;
n = b / y;
if (m > n) m = n;
printf("%I64d", m);
}
return 0;
}
long long int Foo(long long int a, long long int b) {
long long int c = a % b;
if (c == 0) {
return b;
}
return Foo(b, c);
}
| ### Prompt
Construct a cpp code solution to the problem outlined:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
long long int Foo(long long int a, long long int b);
int main() {
long long int a, b, x, y, i, m, n, p;
while (scanf("%lld%lld%lld%lld,", &a, &b, &x, &y) == 4) {
p = Foo(x, y);
x /= p;
y /= p;
m = a / x;
n = b / y;
if (m > n) m = n;
printf("%I64d", m);
}
return 0;
}
long long int Foo(long long int a, long long int b) {
long long int c = a % b;
if (c == 0) {
return b;
}
return Foo(b, c);
}
``` |
#include <bits/stdc++.h>
using namespace std;
inline long long readi() {
long long x;
return scanf("%lld", &x), x;
}
long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
long long a, b, x, y, g;
int main() {
a = readi(), b = readi(), x = readi(), y = readi(), g = gcd(x, y), x /= g,
y /= g;
printf("%lld\n", min(a / x, b / y));
return 0;
}
| ### Prompt
Please provide a CPP coded solution to the problem described below:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
inline long long readi() {
long long x;
return scanf("%lld", &x), x;
}
long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
long long a, b, x, y, g;
int main() {
a = readi(), b = readi(), x = readi(), y = readi(), g = gcd(x, y), x /= g,
y /= g;
printf("%lld\n", min(a / x, b / y));
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
if (a == 0) {
return b;
}
return gcd(b % a, a);
}
int main() {
long long int a, b, x, y;
cin >> a >> b >> x >> y;
long long int g = gcd(min(x, y), max(x, y));
x = x / g;
y = y / g;
long long int ans = min(a / x, b / y);
cout << ans << endl;
return 0;
}
| ### Prompt
Create a solution in cpp for the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
if (a == 0) {
return b;
}
return gcd(b % a, a);
}
int main() {
long long int a, b, x, y;
cin >> a >> b >> x >> y;
long long int g = gcd(min(x, y), max(x, y));
x = x / g;
y = y / g;
long long int ans = min(a / x, b / y);
cout << ans << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return a > 0 ? gcd(b % a, a) : b; }
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long a, b, c, d, k;
cin >> a >> b >> c >> d;
k = gcd(c, d);
c /= k;
d /= k;
cout << min(a / c, b / d);
return 0;
}
| ### Prompt
Your challenge is to write a cpp solution to the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return a > 0 ? gcd(b % a, a) : b; }
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long a, b, c, d, k;
cin >> a >> b >> c >> d;
k = gcd(c, d);
c /= k;
d /= k;
cout << min(a / c, b / d);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (a % b == 0) return b;
return gcd(b, a % b);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long a, b, x, y, k;
cin >> a >> b >> x >> y;
k = gcd(x, y);
x /= k;
y /= k;
cout << min(a / x, b / y) << endl;
return 0;
}
| ### Prompt
Please create a solution in cpp to the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (a % b == 0) return b;
return gcd(b, a % b);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long a, b, x, y, k;
cin >> a >> b >> x >> y;
k = gcd(x, y);
x /= k;
y /= k;
cout << min(a / x, b / y) << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (a == 0) {
return b;
}
return gcd(b % a, a);
}
int main() {
long long a, b, x, y;
cin >> a >> b >> x >> y;
long long g = gcd(x, y);
x /= g;
y /= g;
long long c1 = a / x;
long long c2 = b / y;
long long ans = min(c1, c2);
cout << ans;
return 0;
}
| ### Prompt
Please create a solution in CPP to the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (a == 0) {
return b;
}
return gcd(b % a, a);
}
int main() {
long long a, b, x, y;
cin >> a >> b >> x >> y;
long long g = gcd(x, y);
x /= g;
y /= g;
long long c1 = a / x;
long long c2 = b / y;
long long ans = min(c1, c2);
cout << ans;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long p, long long q) {
if (q == 0) return p;
return gcd(q, p % q);
}
int main() {
long long a, b, p, q;
cin >> a >> b >> p >> q;
long long d = gcd(p, q);
p /= d;
q /= d;
long long ans1 = a / p, ans2 = b / q;
cout << min(ans1, ans2) << endl;
return 0;
}
| ### Prompt
Please create a solution in CPP to the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long p, long long q) {
if (q == 0) return p;
return gcd(q, p % q);
}
int main() {
long long a, b, p, q;
cin >> a >> b >> p >> q;
long long d = gcd(p, q);
p /= d;
q /= d;
long long ans1 = a / p, ans2 = b / q;
cout << min(ans1, ans2) << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int a[1005];
long long gcd(long long a, long long b) {
while (b) {
long long r = a % b;
a = b;
b = r;
}
return a;
}
int main() {
long long a, b, x, y;
cin >> a >> b >> x >> y;
long long a1 = gcd(x, y);
x /= a1;
y /= a1;
cout << min(a / x, b / y);
return 0;
}
| ### Prompt
Please formulate a cpp solution to the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int a[1005];
long long gcd(long long a, long long b) {
while (b) {
long long r = a % b;
a = b;
b = r;
}
return a;
}
int main() {
long long a, b, x, y;
cin >> a >> b >> x >> y;
long long a1 = gcd(x, y);
x /= a1;
y /= a1;
cout << min(a / x, b / y);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long x, long long y) { return y == 0 ? x : gcd(y, x % y); }
int main() {
long long a, b, x, y;
scanf("%lld%lld%lld%lld", &a, &b, &x, &y);
long long t = gcd(x, y);
x /= t;
y /= t;
printf("%lld", min(a / x, b / y));
return 0;
}
| ### Prompt
Generate a CPP solution to the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long x, long long y) { return y == 0 ? x : gcd(y, x % y); }
int main() {
long long a, b, x, y;
scanf("%lld%lld%lld%lld", &a, &b, &x, &y);
long long t = gcd(x, y);
x /= t;
y /= t;
printf("%lld", min(a / x, b / y));
return 0;
}
``` |
#include <bits/stdc++.h>
int main() {
long long a, b, n, m, t2, t1 = 1, x, y;
scanf("%lld %lld %lld %lld", &x, &y, &a, &b);
n = a;
m = b;
while (t1 != 0) {
t1 = a % b;
a = b;
b = t1;
}
n = n / a;
m = m / a;
t1 = x / n;
t2 = y / m;
if (t1 > t2)
printf("%lld", t2);
else
printf("%lld", t1);
return 0;
}
| ### Prompt
Please formulate a Cpp solution to the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
int main() {
long long a, b, n, m, t2, t1 = 1, x, y;
scanf("%lld %lld %lld %lld", &x, &y, &a, &b);
n = a;
m = b;
while (t1 != 0) {
t1 = a % b;
a = b;
b = t1;
}
n = n / a;
m = m / a;
t1 = x / n;
t2 = y / m;
if (t1 > t2)
printf("%lld", t2);
else
printf("%lld", t1);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long int min(long long int a, long long int b) { return a < b ? a : b; }
long long int gcd(long long int a, long long int b) {
if (a == 0) {
return b;
} else {
return gcd(b % a, a);
}
}
int main() {
long long int a, b, x, y;
scanf("%lld%lld%lld%lld", &a, &b, &x, &y);
long long int gc = gcd(x, y);
long long int c1 = x / gc;
long long int c2 = y / gc;
long long int c3 = ((a / c1) < (b / c2) ? a / c1 : b / c2);
printf("%lld\n", c3);
return 0;
}
| ### Prompt
Please provide a CPP coded solution to the problem described below:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long int min(long long int a, long long int b) { return a < b ? a : b; }
long long int gcd(long long int a, long long int b) {
if (a == 0) {
return b;
} else {
return gcd(b % a, a);
}
}
int main() {
long long int a, b, x, y;
scanf("%lld%lld%lld%lld", &a, &b, &x, &y);
long long int gc = gcd(x, y);
long long int c1 = x / gc;
long long int c2 = y / gc;
long long int c3 = ((a / c1) < (b / c2) ? a / c1 : b / c2);
printf("%lld\n", c3);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const unsigned long long mod = 1e9 + 7;
void fast() {
ios::sync_with_stdio(0);
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
}
long long GCD(long long a, long long b) {
if (a == 0) return b;
return GCD(b % a, a);
}
int main() {
unsigned long long a, b, x, y;
cin >> a >> b >> x >> y;
long long g = GCD(x, y);
x /= g;
y /= g;
cout << min(a / x, b / y);
return 0;
}
| ### Prompt
Please create a solution in cpp to the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const unsigned long long mod = 1e9 + 7;
void fast() {
ios::sync_with_stdio(0);
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
}
long long GCD(long long a, long long b) {
if (a == 0) return b;
return GCD(b % a, a);
}
int main() {
unsigned long long a, b, x, y;
cin >> a >> b >> x >> y;
long long g = GCD(x, y);
x /= g;
y /= g;
cout << min(a / x, b / y);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
bool prime[4000005];
void sieve() {
for (int i = 0; i < 4000005; i++) prime[i] = true;
for (int i = 2; i * i <= 4000005; i++) {
if (prime[i] == true) {
for (int x = i * i; x <= 4000005; x += i) {
prime[x] = false;
}
}
}
prime[0] = false;
prime[1] = false;
}
long long int binpow(long long int a, long long int b) {
if (b == 0) return 1;
long long int res = binpow(a, b / 2);
if (b % 2)
return res * res * a;
else
return res * res;
}
long long int gcd(long long int a, long long int b) {
if (a == 0) return b;
return gcd(b % a, a);
}
void sol() {
long long int a, b, x, y;
cin >> a >> b >> x >> y;
long long int num = gcd(x, y);
x = x / num;
y = y / num;
if (a < x || b < y) {
cout << 0 << "\n";
return;
}
cout << min(a / x, b / y) << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
sol();
}
| ### Prompt
Create a solution in cpp for the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
bool prime[4000005];
void sieve() {
for (int i = 0; i < 4000005; i++) prime[i] = true;
for (int i = 2; i * i <= 4000005; i++) {
if (prime[i] == true) {
for (int x = i * i; x <= 4000005; x += i) {
prime[x] = false;
}
}
}
prime[0] = false;
prime[1] = false;
}
long long int binpow(long long int a, long long int b) {
if (b == 0) return 1;
long long int res = binpow(a, b / 2);
if (b % 2)
return res * res * a;
else
return res * res;
}
long long int gcd(long long int a, long long int b) {
if (a == 0) return b;
return gcd(b % a, a);
}
void sol() {
long long int a, b, x, y;
cin >> a >> b >> x >> y;
long long int num = gcd(x, y);
x = x / num;
y = y / num;
if (a < x || b < y) {
cout << 0 << "\n";
return;
}
cout << min(a / x, b / y) << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
sol();
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int a, b, x, y;
cin >> a >> b >> x >> y;
long long int cd = gcd(x, y);
x /= cd;
y /= cd;
long long int count = min(a / x, b / y);
cout << count << endl;
return 0;
}
| ### Prompt
Construct a cpp code solution to the problem outlined:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int a, b, x, y;
cin >> a >> b >> x >> y;
long long int cd = gcd(x, y);
x /= cd;
y /= cd;
long long int count = min(a / x, b / y);
cout << count << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long nsd(long long a, long long b) {
if (a == 0) return b;
if (b == 0) return a;
if (b > a) {
long long temp = b;
b = a;
a = temp;
}
return nsd(a % b, b);
}
int main() {
long long a, b, x, y;
cin >> a >> b >> x >> y;
long long nsdxy = nsd(x, y);
x = x / nsdxy;
y = y / nsdxy;
cout << min(a / x, b / y);
return 0;
}
| ### Prompt
Please create a solution in Cpp to the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long nsd(long long a, long long b) {
if (a == 0) return b;
if (b == 0) return a;
if (b > a) {
long long temp = b;
b = a;
a = temp;
}
return nsd(a % b, b);
}
int main() {
long long a, b, x, y;
cin >> a >> b >> x >> y;
long long nsdxy = nsd(x, y);
x = x / nsdxy;
y = y / nsdxy;
cout << min(a / x, b / y);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long cmmdc(long long a, long long b) {
long long r;
while (a > 0) {
r = b % a;
b = a;
a = r;
}
return b;
}
int main() {
long long a, b, x, y;
cin >> a >> b >> x >> y;
long long xy = cmmdc(x, y);
x /= xy;
y /= xy;
cout << min(a / x, b / y);
}
| ### Prompt
Please provide a CPP coded solution to the problem described below:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long cmmdc(long long a, long long b) {
long long r;
while (a > 0) {
r = b % a;
b = a;
a = r;
}
return b;
}
int main() {
long long a, b, x, y;
cin >> a >> b >> x >> y;
long long xy = cmmdc(x, y);
x /= xy;
y /= xy;
cout << min(a / x, b / y);
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (b == 0) {
return a;
} else {
return gcd(b, a % b);
}
}
int main() {
long long a, b, x, y;
cin >> a >> b >> x >> y;
long long sb = gcd(x, y);
x = x / sb;
y = y / sb;
cout << min(a / x, b / y) << endl;
return 0;
}
| ### Prompt
Develop a solution in CPP to the problem described below:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (b == 0) {
return a;
} else {
return gcd(b, a % b);
}
}
int main() {
long long a, b, x, y;
cin >> a >> b >> x >> y;
long long sb = gcd(x, y);
x = x / sb;
y = y / sb;
cout << min(a / x, b / y) << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
return b ? gcd(b, a % b) : a;
}
const int MAX = 1e6 + 7;
int main() {
long long int a, b, x, y;
cin >> a >> b >> x >> y;
long long int d = gcd(x, y);
x /= d;
y /= d;
long long int res = min(a / x, b / y);
cout << res << endl;
return 0;
}
| ### Prompt
Please formulate a cpp solution to the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
return b ? gcd(b, a % b) : a;
}
const int MAX = 1e6 + 7;
int main() {
long long int a, b, x, y;
cin >> a >> b >> x >> y;
long long int d = gcd(x, y);
x /= d;
y /= d;
long long int res = min(a / x, b / y);
cout << res << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
constexpr int MOD = 1000000007;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
os << "[";
for (const auto &v : vec) {
os << v << ",";
}
os << "]";
return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << "(" << p.first << ", " << p.second << ")";
return os;
}
long long gcd(long long a, long long b) {
if (a % b == 0) return b;
return gcd(b, a % b);
}
void solve() {
long long a, b, x, y;
cin >> a >> b >> x >> y;
long long g = gcd(x, y);
x /= g;
y /= g;
long long p1 = a / x;
long long p2 = b / y;
cout << min(p1, p2) << endl;
}
int main() {
std::cin.tie(0);
std::ios::sync_with_stdio(false);
cout.setf(ios::fixed);
cout.precision(16);
solve();
return 0;
}
| ### Prompt
Generate a CPP solution to the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
constexpr int MOD = 1000000007;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
os << "[";
for (const auto &v : vec) {
os << v << ",";
}
os << "]";
return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << "(" << p.first << ", " << p.second << ")";
return os;
}
long long gcd(long long a, long long b) {
if (a % b == 0) return b;
return gcd(b, a % b);
}
void solve() {
long long a, b, x, y;
cin >> a >> b >> x >> y;
long long g = gcd(x, y);
x /= g;
y /= g;
long long p1 = a / x;
long long p2 = b / y;
cout << min(p1, p2) << endl;
}
int main() {
std::cin.tie(0);
std::ios::sync_with_stdio(false);
cout.setf(ios::fixed);
cout.precision(16);
solve();
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int ddx[8] = {0, 0, 1, 1, 1, -1, -1, -1}, ddy[8] = {1, -1, 1, 0, -1, 1, 0, -1};
long long MOD = 1000000000;
long long POW(long long a, long long b, long long MMM = MOD) {
long long ret = 1;
for (; b; b >>= 1, a = (a * a) % MMM)
if (b & 1) ret = (ret * a) % MMM;
return ret;
}
long long GCD(long long a, long long b) { return b ? GCD(b, a % b) : a; }
long long LCM(long long a, long long b) {
if (a == 0 || b == 0) return a + b;
return a * (b / GCD(a, b));
}
bool OOB(long long x, long long y, long long N, long long M) {
return 0 > x || x >= N || 0 > y || y >= M;
}
int main() {
long long a, b, x, y;
cin >> a >> b >> x >> y;
long long g = GCD(x, y);
long long x1 = x / g;
long long y1 = y / g;
long long ans1 = a / x1;
long long ans2 = b / y1;
long long ans = min(ans1, ans2);
cout << (ans) << '\n';
return 0;
}
| ### Prompt
Please provide a CPP coded solution to the problem described below:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int ddx[8] = {0, 0, 1, 1, 1, -1, -1, -1}, ddy[8] = {1, -1, 1, 0, -1, 1, 0, -1};
long long MOD = 1000000000;
long long POW(long long a, long long b, long long MMM = MOD) {
long long ret = 1;
for (; b; b >>= 1, a = (a * a) % MMM)
if (b & 1) ret = (ret * a) % MMM;
return ret;
}
long long GCD(long long a, long long b) { return b ? GCD(b, a % b) : a; }
long long LCM(long long a, long long b) {
if (a == 0 || b == 0) return a + b;
return a * (b / GCD(a, b));
}
bool OOB(long long x, long long y, long long N, long long M) {
return 0 > x || x >= N || 0 > y || y >= M;
}
int main() {
long long a, b, x, y;
cin >> a >> b >> x >> y;
long long g = GCD(x, y);
long long x1 = x / g;
long long y1 = y / g;
long long ans1 = a / x1;
long long ans2 = b / y1;
long long ans = min(ans1, ans2);
cout << (ans) << '\n';
return 0;
}
``` |
#include <bits/stdc++.h>
#pragma gcc optimize(o3)
using namespace std;
long long qpow(long long x, long long y) {
return y ? (y & 1 ? x * qpow(x, y - 1) % 1000000007
: qpow(x * x % 1000000007, y / 2))
: 1;
}
template <typename T>
inline void read(T& x) {
x = 0;
char c;
int sign = 1;
do {
c = getchar();
if (c == '-') sign = -1;
} while (!isdigit(c));
do {
x = x * 10 + c - '0';
c = getchar();
} while (isdigit(c));
x *= sign;
}
long long a, b, x, y, k;
long long gcd(long long p, long long q) {
if (q == 0) return p;
return gcd(q, p % q);
}
int main() {
read(a), read(b), read(x), read(y);
k = gcd(x, y);
x /= k, y /= k;
printf("%I64d\n", min(a / x, b / y));
return 0;
}
| ### Prompt
Create a solution in cpp for the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
#pragma gcc optimize(o3)
using namespace std;
long long qpow(long long x, long long y) {
return y ? (y & 1 ? x * qpow(x, y - 1) % 1000000007
: qpow(x * x % 1000000007, y / 2))
: 1;
}
template <typename T>
inline void read(T& x) {
x = 0;
char c;
int sign = 1;
do {
c = getchar();
if (c == '-') sign = -1;
} while (!isdigit(c));
do {
x = x * 10 + c - '0';
c = getchar();
} while (isdigit(c));
x *= sign;
}
long long a, b, x, y, k;
long long gcd(long long p, long long q) {
if (q == 0) return p;
return gcd(q, p % q);
}
int main() {
read(a), read(b), read(x), read(y);
k = gcd(x, y);
x /= k, y /= k;
printf("%I64d\n", min(a / x, b / y));
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long int GCD(long long int a, long long int b) {
if (a == 0) {
return b;
}
return GCD(b % a, a);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
;
int q;
long long int a, b, x, y;
cin >> a >> b >> x >> y;
long long int gc = GCD(x, y);
x = x / gc;
y = y / gc;
cout << min(a / x, b / y) << endl;
}
| ### Prompt
In cpp, your task is to solve the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long int GCD(long long int a, long long int b) {
if (a == 0) {
return b;
}
return GCD(b % a, a);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
;
int q;
long long int a, b, x, y;
cin >> a >> b >> x >> y;
long long int gc = GCD(x, y);
x = x / gc;
y = y / gc;
cout << min(a / x, b / y) << endl;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int oo = 0x7fffffff;
const long long OO = 0x7fffffffffffffff;
long long gcd(long long a, long long b) {
while (b) {
a %= b;
swap(a, b);
}
return a;
}
int main() {
ios_base::sync_with_stdio(false);
long long a, b, x, y, g;
cin >> a >> b >> x >> y;
g = gcd(x, y);
x /= g;
y /= g;
cout << min(a / x, b / y) << endl;
return 0;
}
| ### Prompt
Your task is to create a cpp solution to the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int oo = 0x7fffffff;
const long long OO = 0x7fffffffffffffff;
long long gcd(long long a, long long b) {
while (b) {
a %= b;
swap(a, b);
}
return a;
}
int main() {
ios_base::sync_with_stdio(false);
long long a, b, x, y, g;
cin >> a >> b >> x >> y;
g = gcd(x, y);
x /= g;
y /= g;
cout << min(a / x, b / y) << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long int GCD(long long int x, long long int y) {
if (x % y == 0)
return y;
else
return GCD(y, x % y);
}
int main() {
long long int a, b, x, y;
cin >> a >> b >> x >> y;
long long int gcd = GCD(x, y);
long long int reduced_x = x / gcd;
long long int reduced_y = y / gcd;
long long int m = a / reduced_x;
long long int n = b / reduced_y;
cout << min(m, n);
}
| ### Prompt
Develop a solution in CPP to the problem described below:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long int GCD(long long int x, long long int y) {
if (x % y == 0)
return y;
else
return GCD(y, x % y);
}
int main() {
long long int a, b, x, y;
cin >> a >> b >> x >> y;
long long int gcd = GCD(x, y);
long long int reduced_x = x / gcd;
long long int reduced_y = y / gcd;
long long int m = a / reduced_x;
long long int n = b / reduced_y;
cout << min(m, n);
}
``` |
#include <bits/stdc++.h>
long long a, b, x, y;
long long gcd(long long q, long long w) {
if (!w) return q;
return gcd(w, q % w);
}
int main() {
scanf("%I64d %I64d %I64d %I64d", &a, &b, &x, &y);
long long G = gcd(x, y);
x /= G;
y /= G;
long long ans = std::min((long long)(a / x), (long long)(b / y));
printf("%I64d", ans);
return 0;
}
| ### Prompt
Construct a cpp code solution to the problem outlined:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
long long a, b, x, y;
long long gcd(long long q, long long w) {
if (!w) return q;
return gcd(w, q % w);
}
int main() {
scanf("%I64d %I64d %I64d %I64d", &a, &b, &x, &y);
long long G = gcd(x, y);
x /= G;
y /= G;
long long ans = std::min((long long)(a / x), (long long)(b / y));
printf("%I64d", ans);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace ::std;
long long int gcd(long long int a, long long int b) {
while (b) {
a %= b;
swap(a, b);
}
return a;
}
int main() {
long long int a, b, x, y;
cin >> a >> b >> x >> y;
long long int div = gcd(x, y);
x /= div;
y /= div;
cout << min(a / x, b / y);
}
| ### Prompt
Develop a solution in CPP to the problem described below:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace ::std;
long long int gcd(long long int a, long long int b) {
while (b) {
a %= b;
swap(a, b);
}
return a;
}
int main() {
long long int a, b, x, y;
cin >> a >> b >> x >> y;
long long int div = gcd(x, y);
x /= div;
y /= div;
cout << min(a / x, b / y);
}
``` |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
char c = getchar();
long long num = 0;
long long f = 1;
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
num = (num << 3) + (num << 1) + (c ^ 48);
c = getchar();
}
return num * f;
}
inline void qwq(long long x) {
if (x > 9) qwq(x / 10);
putchar(x % 10 + '0');
}
inline void write(long long x) {
if (x < 0) {
x = -x;
putchar('-');
}
qwq(x);
putchar('\n');
}
inline long long gcd(long long x, long long y) {
if (x % y == 0)
return y;
else
return gcd(y, x % y);
}
int main() {
long long a = read();
long long b = read();
long long x = read();
long long y = read();
long long temp = gcd(x, y);
x /= temp;
y /= temp;
if (a < x || b < y) {
write(0);
return 0;
}
long long ans = min(a / x, b / y);
write(ans);
return 0;
}
| ### Prompt
Please formulate a cpp solution to the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
char c = getchar();
long long num = 0;
long long f = 1;
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
num = (num << 3) + (num << 1) + (c ^ 48);
c = getchar();
}
return num * f;
}
inline void qwq(long long x) {
if (x > 9) qwq(x / 10);
putchar(x % 10 + '0');
}
inline void write(long long x) {
if (x < 0) {
x = -x;
putchar('-');
}
qwq(x);
putchar('\n');
}
inline long long gcd(long long x, long long y) {
if (x % y == 0)
return y;
else
return gcd(y, x % y);
}
int main() {
long long a = read();
long long b = read();
long long x = read();
long long y = read();
long long temp = gcd(x, y);
x /= temp;
y /= temp;
if (a < x || b < y) {
write(0);
return 0;
}
long long ans = min(a / x, b / y);
write(ans);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long a, b, x, y;
long long MY_gcd(long long a, long long b) {
if (b == 0) return a;
return MY_gcd(b, a % b);
}
int main() {
scanf("%lld%lld%lld%lld", &a, &b, &x, &y);
long long GCD = MY_gcd(x, y);
x /= GCD;
y /= GCD;
long long t1 = a / x;
long long t2 = b / y;
printf("%lld", min(t1, t2));
return 0;
}
| ### Prompt
Please create a solution in Cpp to the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long a, b, x, y;
long long MY_gcd(long long a, long long b) {
if (b == 0) return a;
return MY_gcd(b, a % b);
}
int main() {
scanf("%lld%lld%lld%lld", &a, &b, &x, &y);
long long GCD = MY_gcd(x, y);
x /= GCD;
y /= GCD;
long long t1 = a / x;
long long t2 = b / y;
printf("%lld", min(t1, t2));
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long a;
long long b;
long long x;
long long y;
long long calculateGcd(long long a, long long b) {
long long gcd = b;
long long c = a % b;
while (c > 0) {
a = b;
b = c;
c = a % b;
if (c <= 0) {
gcd = b;
break;
}
}
return gcd;
}
int main() {
cin >> a >> b >> x >> y;
long long gcd = calculateGcd(x, y);
if (gcd != 0) {
x = x / gcd;
y = y / gcd;
}
long long ax = a / x;
long long by = b / y;
if (ax < by) {
cout << ax << endl;
} else {
cout << by << endl;
}
}
| ### Prompt
Generate a cpp solution to the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long a;
long long b;
long long x;
long long y;
long long calculateGcd(long long a, long long b) {
long long gcd = b;
long long c = a % b;
while (c > 0) {
a = b;
b = c;
c = a % b;
if (c <= 0) {
gcd = b;
break;
}
}
return gcd;
}
int main() {
cin >> a >> b >> x >> y;
long long gcd = calculateGcd(x, y);
if (gcd != 0) {
x = x / gcd;
y = y / gcd;
}
long long ax = a / x;
long long by = b / y;
if (ax < by) {
cout << ax << endl;
} else {
cout << by << endl;
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long a, b, c, d;
long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
int main() {
scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
long long ans = gcd(c, d);
long long ans1 = c / ans;
long long ans2 = d / ans;
ans = min(a / ans1, b / ans2);
printf("%lld\n", ans);
return 0;
}
| ### Prompt
Construct a CPP code solution to the problem outlined:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long a, b, c, d;
long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
int main() {
scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
long long ans = gcd(c, d);
long long ans1 = c / ans;
long long ans2 = d / ans;
ans = min(a / ans1, b / ans2);
printf("%lld\n", ans);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const long long MAX = 1000;
const long long MAXN = 1000;
const double PI = acos(-1.0);
long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
int main() {
long long a, b, x, y;
cin >> a >> b >> x >> y;
long long minn = x > y ? gcd(x, y) : gcd(y, x);
x /= minn, y /= minn;
cout << (min(a / x, b / y));
return 0;
}
| ### Prompt
In CPP, your task is to solve the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const long long MAX = 1000;
const long long MAXN = 1000;
const double PI = acos(-1.0);
long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
int main() {
long long a, b, x, y;
cin >> a >> b >> x >> y;
long long minn = x > y ? gcd(x, y) : gcd(y, x);
x /= minn, y /= minn;
cout << (min(a / x, b / y));
return 0;
}
``` |
#include <bits/stdc++.h>
unsigned long long gcd(unsigned long long a, unsigned long long b) {
while (a != 0 && b != 0) {
if (a > b)
a %= b;
else
b %= a;
}
return a + b;
}
int task_A() {
int n;
std::cin >> n;
std::vector<int> keyboards(n, 0);
for (int i = 0; i < n; ++i) {
std::cin >> keyboards[i];
}
std::sort(keyboards.begin(), keyboards.end());
int missing_keyboards = 0;
for (int i = 1; i < keyboards.size(); ++i) {
missing_keyboards += (keyboards[i] - keyboards[i - 1] - 1);
}
std::cout << missing_keyboards << std::endl;
return 0;
}
int task_B() {
unsigned long long a, b, x, y;
std::cin >> a >> b >> x >> y;
unsigned long long g = gcd(x, y);
x /= g;
y /= g;
unsigned long long answer = std::min(a / x, b / y);
std::cout << answer << std::endl;
return 0;
}
int main() {
task_B();
return 0;
}
| ### Prompt
Generate a Cpp solution to the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
unsigned long long gcd(unsigned long long a, unsigned long long b) {
while (a != 0 && b != 0) {
if (a > b)
a %= b;
else
b %= a;
}
return a + b;
}
int task_A() {
int n;
std::cin >> n;
std::vector<int> keyboards(n, 0);
for (int i = 0; i < n; ++i) {
std::cin >> keyboards[i];
}
std::sort(keyboards.begin(), keyboards.end());
int missing_keyboards = 0;
for (int i = 1; i < keyboards.size(); ++i) {
missing_keyboards += (keyboards[i] - keyboards[i - 1] - 1);
}
std::cout << missing_keyboards << std::endl;
return 0;
}
int task_B() {
unsigned long long a, b, x, y;
std::cin >> a >> b >> x >> y;
unsigned long long g = gcd(x, y);
x /= g;
y /= g;
unsigned long long answer = std::min(a / x, b / y);
std::cout << answer << std::endl;
return 0;
}
int main() {
task_B();
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long nod(long long a, long long b) {
while (a != 0 && b != 0) {
if (a > b) {
a %= b;
} else {
b %= a;
}
}
return a + b;
}
signed main() {
long long a, b, x, y;
cin >> a >> b >> x >> y;
long long l = nod(x, y);
x /= l;
y /= l;
cout << min(a / x, b / y);
return 0;
}
| ### Prompt
Please formulate a cpp solution to the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long nod(long long a, long long b) {
while (a != 0 && b != 0) {
if (a > b) {
a %= b;
} else {
b %= a;
}
}
return a + b;
}
signed main() {
long long a, b, x, y;
cin >> a >> b >> x >> y;
long long l = nod(x, y);
x /= l;
y /= l;
cout << min(a / x, b / y);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
void solve();
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
{
solve();
cout << "\n";
}
cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
return 0;
}
long long ceils(long long x, long long y) { return x / y + ((x % y) != 0); }
long long mult(long long x, long long y, long long mod) {
return (x * y) % mod;
}
long long bin_pow(long long x, long long p, long long mod) {
if (p == 0) return 1;
if (p & 1) return mult(bin_pow(x, p - 1, mod), x, mod);
return bin_pow(mult(x, x, mod), p / 2, mod);
}
bool isPrime(long long n) {
if (n <= 1) return false;
if (n <= 3) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
for (long long i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0) return false;
return true;
}
vector<bool> is_prime(1e6 + 1, true);
long long binomialCoeffSpaceEff(long long n, long long k) {
long long C[k + 1];
memset(C, 0, sizeof(C));
C[0] = 1;
for (long long i = 1; i <= n; i++) {
for (long long j = min(i, k); j > 0; j--) C[j] = (C[j] + C[j - 1]) % MOD;
}
return C[k];
}
long long primeFactors(long long n) {
vector<long long> ar;
long long i = 2;
while (n > 0) {
if (i > n) break;
if (n % i == 0) {
ar.push_back(i);
while (n > 0 and n % i == 0) n = n / i;
}
i++;
}
return ar.size();
}
vector<pair<long long, long long> > primeFactorsFreq(long long n) {
vector<pair<long long, long long> > ar;
long long i = 2;
while (n > 0) {
if (i > n) break;
if (n % i == 0) {
long long cnt = 0;
while (n > 0 and n % i == 0) n = n / i, cnt++;
ar.push_back(make_pair(i, cnt));
}
i++;
}
return ar;
}
void seive() {
is_prime[0] = is_prime[1] = false;
for (long long i = 2; i * i <= 1e6 + 1; i++) {
if (is_prime[i]) {
for (long long j = i * i; j <= 1e6 + 1; j += i) is_prime[j] = false;
}
}
}
bool isSorted(vector<long long> &ar) {
long long n = ar.size();
for (long long i = 0; i < n - 1; i++) {
if (ar[i + 1] < ar[i]) return false;
}
return true;
}
long long fastPower(long long x, long long y) {
long long res = 1;
while (y > 0) {
if (y & 1) res = (res * x) % MOD;
y = y >> 1;
x = (x * x) % MOD;
}
return res;
}
long long kadanesAlgo(vector<long long> ar) {
long long n = ar.size();
long long currMax = 0;
long long mx = INT_MIN;
for (long long i = 0; i < n; i++) {
currMax += ar[i];
if (currMax <= ar[i]) {
currMax = ar[i];
}
mx = max(currMax, mx);
}
return mx;
}
pair<long long, long long> kadanesAlgoIdx(vector<long long> ar) {
long long n = ar.size();
long long currMax = 0;
long long mx = INT_MIN;
long long a = 0, b;
for (long long i = 0; i < n; i++) {
currMax += ar[i];
if (currMax <= ar[i]) {
currMax = ar[i];
a = i;
}
if (mx < currMax) {
mx = currMax;
b = i;
}
}
return make_pair(a, b);
}
long long gcd(long long a, long long b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long fac(long long n) {
while (n % 4 == 0) {
n /= 4;
}
for (long long i = 3; i <= sqrt(n); i += 2) {
while (n % (i * i) == 0) {
n /= (i * i);
}
}
return n;
}
long long findLCS(string a, string b, long long m, long long n) {
long long LCS[m + 1][n + 1];
long long result = 0;
for (long long i = 0; i <= m; i++) {
for (long long j = 0; j <= n; j++) {
if (i == 0 || j == 0)
LCS[i][j] = 0;
else if (a[i - 1] == b[j - 1]) {
LCS[i][j] = LCS[i - 1][j - 1] + 1;
result = max(result, LCS[i][j]);
} else
LCS[i][j] = 0;
}
}
return result;
}
long long add(long long x, long long y) {
x += y;
if (x >= MOD) return x - MOD;
return x;
}
long long sub(long long x, long long y) {
x -= y;
if (x < 0) return x + MOD;
return x;
}
long long f(long long x) {
long long d = 0;
while (x > 0) {
d += x % 10;
x /= 10;
}
return d;
}
vector<string> generateGray(long long n) {
if (n <= 0) return {"0"};
if (n == 1) {
return {"0", "1"};
}
vector<string> recAns = generateGray(n - 1);
vector<string> mainAns;
for (long long i = 0; i < recAns.size(); i++) {
string s = recAns[i];
mainAns.push_back("0" + s);
}
for (long long i = recAns.size() - 1; i >= 0; i--) {
string s = recAns[i];
mainAns.push_back("1" + s);
}
return mainAns;
}
void generateGraya(long long n) {
vector<string> a;
a = generateGray(n);
for (long long i = 0; i < a.size(); i++) cout << a[i] << endl;
}
void move(long long disks, long long source, long long auxiliary,
long long target) {
if (disks > 0) {
move(disks - 1, source, target, auxiliary);
cout << source << " " << target << endl;
move(disks - 1, auxiliary, source, target);
}
}
long double polyarea(long double n, long double a) {
if (a < 0 && n < 0) return -1;
long double A = (a * a * n) / (4 * tan((180 / n) * 3.14159 / 180));
return A;
}
long long eqDiv(long long *a, long long s1, long long s, long long l) {
if (l == 0) return abs((s - s1) - s1);
return min(eqDiv(a, s1 + a[l], s, l - 1), eqDiv(a, s1, s, l - 1));
}
long long noofdigit(long long n) {
long long x = 0;
while (n > 0) {
n /= 10;
x++;
}
return x;
}
long long factorial(long long n) {
if (n == 0) return 1;
return (n * factorial(n - 1) % MOD) % MOD;
}
void solve() {
long long a, b, x, y;
cin >> a >> b >> x >> y;
while (gcd(x, y) != 1) {
long long t = gcd(x, y);
x /= t;
y /= t;
}
long long fin = min(a / x, b / y);
cout << fin;
}
| ### Prompt
Construct a cpp code solution to the problem outlined:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
void solve();
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
{
solve();
cout << "\n";
}
cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
return 0;
}
long long ceils(long long x, long long y) { return x / y + ((x % y) != 0); }
long long mult(long long x, long long y, long long mod) {
return (x * y) % mod;
}
long long bin_pow(long long x, long long p, long long mod) {
if (p == 0) return 1;
if (p & 1) return mult(bin_pow(x, p - 1, mod), x, mod);
return bin_pow(mult(x, x, mod), p / 2, mod);
}
bool isPrime(long long n) {
if (n <= 1) return false;
if (n <= 3) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
for (long long i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0) return false;
return true;
}
vector<bool> is_prime(1e6 + 1, true);
long long binomialCoeffSpaceEff(long long n, long long k) {
long long C[k + 1];
memset(C, 0, sizeof(C));
C[0] = 1;
for (long long i = 1; i <= n; i++) {
for (long long j = min(i, k); j > 0; j--) C[j] = (C[j] + C[j - 1]) % MOD;
}
return C[k];
}
long long primeFactors(long long n) {
vector<long long> ar;
long long i = 2;
while (n > 0) {
if (i > n) break;
if (n % i == 0) {
ar.push_back(i);
while (n > 0 and n % i == 0) n = n / i;
}
i++;
}
return ar.size();
}
vector<pair<long long, long long> > primeFactorsFreq(long long n) {
vector<pair<long long, long long> > ar;
long long i = 2;
while (n > 0) {
if (i > n) break;
if (n % i == 0) {
long long cnt = 0;
while (n > 0 and n % i == 0) n = n / i, cnt++;
ar.push_back(make_pair(i, cnt));
}
i++;
}
return ar;
}
void seive() {
is_prime[0] = is_prime[1] = false;
for (long long i = 2; i * i <= 1e6 + 1; i++) {
if (is_prime[i]) {
for (long long j = i * i; j <= 1e6 + 1; j += i) is_prime[j] = false;
}
}
}
bool isSorted(vector<long long> &ar) {
long long n = ar.size();
for (long long i = 0; i < n - 1; i++) {
if (ar[i + 1] < ar[i]) return false;
}
return true;
}
long long fastPower(long long x, long long y) {
long long res = 1;
while (y > 0) {
if (y & 1) res = (res * x) % MOD;
y = y >> 1;
x = (x * x) % MOD;
}
return res;
}
long long kadanesAlgo(vector<long long> ar) {
long long n = ar.size();
long long currMax = 0;
long long mx = INT_MIN;
for (long long i = 0; i < n; i++) {
currMax += ar[i];
if (currMax <= ar[i]) {
currMax = ar[i];
}
mx = max(currMax, mx);
}
return mx;
}
pair<long long, long long> kadanesAlgoIdx(vector<long long> ar) {
long long n = ar.size();
long long currMax = 0;
long long mx = INT_MIN;
long long a = 0, b;
for (long long i = 0; i < n; i++) {
currMax += ar[i];
if (currMax <= ar[i]) {
currMax = ar[i];
a = i;
}
if (mx < currMax) {
mx = currMax;
b = i;
}
}
return make_pair(a, b);
}
long long gcd(long long a, long long b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long fac(long long n) {
while (n % 4 == 0) {
n /= 4;
}
for (long long i = 3; i <= sqrt(n); i += 2) {
while (n % (i * i) == 0) {
n /= (i * i);
}
}
return n;
}
long long findLCS(string a, string b, long long m, long long n) {
long long LCS[m + 1][n + 1];
long long result = 0;
for (long long i = 0; i <= m; i++) {
for (long long j = 0; j <= n; j++) {
if (i == 0 || j == 0)
LCS[i][j] = 0;
else if (a[i - 1] == b[j - 1]) {
LCS[i][j] = LCS[i - 1][j - 1] + 1;
result = max(result, LCS[i][j]);
} else
LCS[i][j] = 0;
}
}
return result;
}
long long add(long long x, long long y) {
x += y;
if (x >= MOD) return x - MOD;
return x;
}
long long sub(long long x, long long y) {
x -= y;
if (x < 0) return x + MOD;
return x;
}
long long f(long long x) {
long long d = 0;
while (x > 0) {
d += x % 10;
x /= 10;
}
return d;
}
vector<string> generateGray(long long n) {
if (n <= 0) return {"0"};
if (n == 1) {
return {"0", "1"};
}
vector<string> recAns = generateGray(n - 1);
vector<string> mainAns;
for (long long i = 0; i < recAns.size(); i++) {
string s = recAns[i];
mainAns.push_back("0" + s);
}
for (long long i = recAns.size() - 1; i >= 0; i--) {
string s = recAns[i];
mainAns.push_back("1" + s);
}
return mainAns;
}
void generateGraya(long long n) {
vector<string> a;
a = generateGray(n);
for (long long i = 0; i < a.size(); i++) cout << a[i] << endl;
}
void move(long long disks, long long source, long long auxiliary,
long long target) {
if (disks > 0) {
move(disks - 1, source, target, auxiliary);
cout << source << " " << target << endl;
move(disks - 1, auxiliary, source, target);
}
}
long double polyarea(long double n, long double a) {
if (a < 0 && n < 0) return -1;
long double A = (a * a * n) / (4 * tan((180 / n) * 3.14159 / 180));
return A;
}
long long eqDiv(long long *a, long long s1, long long s, long long l) {
if (l == 0) return abs((s - s1) - s1);
return min(eqDiv(a, s1 + a[l], s, l - 1), eqDiv(a, s1, s, l - 1));
}
long long noofdigit(long long n) {
long long x = 0;
while (n > 0) {
n /= 10;
x++;
}
return x;
}
long long factorial(long long n) {
if (n == 0) return 1;
return (n * factorial(n - 1) % MOD) % MOD;
}
void solve() {
long long a, b, x, y;
cin >> a >> b >> x >> y;
while (gcd(x, y) != 1) {
long long t = gcd(x, y);
x /= t;
y /= t;
}
long long fin = min(a / x, b / y);
cout << fin;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long a, b, x, y;
inline long long read() {
long long x = 0, f = 1;
char ch;
for (ch = getchar(); !isdigit(ch); ch = getchar())
if (ch == '-') f = -1;
for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + ch - '0';
return x * f;
}
long long gcd(long long x, long long y) {
if (!y) return x;
return gcd(y, x % y);
}
int main() {
a = read(), b = read(), x = read(), y = read();
long long g = gcd(x, y);
x /= g, y = y /= g;
printf("%I64d\n", min(a / x, b / y));
return 0;
}
| ### Prompt
In CPP, your task is to solve the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long a, b, x, y;
inline long long read() {
long long x = 0, f = 1;
char ch;
for (ch = getchar(); !isdigit(ch); ch = getchar())
if (ch == '-') f = -1;
for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + ch - '0';
return x * f;
}
long long gcd(long long x, long long y) {
if (!y) return x;
return gcd(y, x % y);
}
int main() {
a = read(), b = read(), x = read(), y = read();
long long g = gcd(x, y);
x /= g, y = y /= g;
printf("%I64d\n", min(a / x, b / y));
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long nod(long long num, long long den);
int main() {
long long a, b, x, y, numH, numL, del;
cin >> a >> b >> x >> y;
del = nod(x, y);
x = x / del;
y = y / del;
numL = a / x;
numH = b / y;
if (numL > numH)
cout << numH;
else
cout << numL;
}
long long nod(long long num, long long den) {
if (den == 0)
return num;
else
return nod(den, num % den);
}
| ### Prompt
Please formulate a CPP solution to the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long nod(long long num, long long den);
int main() {
long long a, b, x, y, numH, numL, del;
cin >> a >> b >> x >> y;
del = nod(x, y);
x = x / del;
y = y / del;
numL = a / x;
numH = b / y;
if (numL > numH)
cout << numH;
else
cout << numL;
}
long long nod(long long num, long long den) {
if (den == 0)
return num;
else
return nod(den, num % den);
}
``` |
#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
return os << "(" << p.first << "," << p.second << ")";
}
template <typename T>
inline ostream& operator<<(ostream& os, const vector<T>& v) {
bool first = true;
os << "{";
for (unsigned int i = 0; i < v.size(); i++) {
if (!first) os << ",";
os << v[i];
first = false;
}
return os << "}";
}
template <typename T>
inline ostream& operator<<(ostream& os, const set<T>& v) {
bool first = true;
os << "{";
for (typename set<T>::const_iterator ii = v.begin(); ii != v.end(); ++ii) {
if (!first) os << ",";
os << *ii;
first = false;
}
return os << "}";
}
template <typename T>
inline ostream& operator<<(ostream& os, const multiset<T>& v) {
bool first = true;
os << "{";
for (typename multiset<T>::const_iterator ii = v.begin(); ii != v.end();
++ii) {
if (!first) os << ",";
os << *ii;
first = false;
}
return os << "}";
}
template <typename T1, typename T2>
inline ostream& operator<<(ostream& os, const map<T1, T2>& v) {
bool first = true;
os << "{";
for (typename map<T1, T2>::const_iterator ii = v.begin(); ii != v.end();
++ii) {
if (!first) os << ",";
os << *ii;
first = false;
}
return os << "}";
}
template <typename T>
bool isPrime(T n) {
T i, lmt = sqrt(n);
for (i = 2; i <= lmt; i++)
if (n % i == 0) return false;
return true;
}
template <typename T>
T gcd(T a, T b) {
if (b == 0) return a;
return gcd(b, a % b);
}
template <typename T>
T BigMod(T b, T p, T m) {
if (p == 0)
return 1 % m;
else if (p & 1)
return ((b % m) * (BigMod(b, p - 1, m) % m)) % m;
else {
T s = BigMod(b, p / 2, m);
return ((s % m) * (s % m)) % m;
}
}
template <typename T>
T power(T b, T p) {
if (p == 0)
return 1;
else if (p & 1)
return b * power(b, p - 1);
else {
T ret = power(b, p / 2);
return ret * ret;
}
}
template <typename T>
T ModInv(T b, T m) {
if (isPrime(b))
return BigMod(b, m - 2, m) % m;
else if (gcd(b, m) == 1)
return BigMod(b, m - 1, m) % m;
}
template <typename T>
T egcd(T a, T b, T& x, T& y) {
T d;
if (a == 0) {
x = 0;
y = 1;
return b;
} else {
T x1, y1;
d = egcd(b % a, a, x1, y1);
x = y1 - (b / a) * x1;
y = x1;
}
return d;
}
int toint(string s) {
int i, j, l;
int num;
l = s.size();
for (i = l - 1, j = 0, num = 0; i >= 0; i--, j++) {
num += (s[i] - 48) * power(10, j);
}
return num;
}
const double pi = acos(-1);
const int inf = (1 << 30);
const long long INF = (1LL << 62) - 1;
const int mod = (int)1e9 + 7;
const long long MOD = (long long)1e9 + 7;
const double EPS = 1e-9;
const int dx8[] = {-1, 0, +1, -1, +1, -1, 0, +1};
const int dy8[] = {+1, +1, +1, 0, 0, -1, -1, -1};
const int dx4[] = {0, -1, +1, 0};
const int dy4[] = {+1, 0, 0, -1};
const int dx2[] = {+1, 0};
const int dy2[] = {0, +1};
const int dxkn[] = {1, -1, 1, -1, 2, -2, -2, 2};
const int dykn[] = {2, 2, -2, -2, 1, 1, -1, -1};
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long a, b, x, y, l1, l2, ans, g;
cin >> a >> b >> x >> y;
g = gcd(x, y);
x = x / g;
y = y / g;
l1 = a / x;
l2 = b / y;
ans = min(l1, l2);
cout << ans << "\n";
return 0;
}
| ### Prompt
Construct a Cpp code solution to the problem outlined:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
return os << "(" << p.first << "," << p.second << ")";
}
template <typename T>
inline ostream& operator<<(ostream& os, const vector<T>& v) {
bool first = true;
os << "{";
for (unsigned int i = 0; i < v.size(); i++) {
if (!first) os << ",";
os << v[i];
first = false;
}
return os << "}";
}
template <typename T>
inline ostream& operator<<(ostream& os, const set<T>& v) {
bool first = true;
os << "{";
for (typename set<T>::const_iterator ii = v.begin(); ii != v.end(); ++ii) {
if (!first) os << ",";
os << *ii;
first = false;
}
return os << "}";
}
template <typename T>
inline ostream& operator<<(ostream& os, const multiset<T>& v) {
bool first = true;
os << "{";
for (typename multiset<T>::const_iterator ii = v.begin(); ii != v.end();
++ii) {
if (!first) os << ",";
os << *ii;
first = false;
}
return os << "}";
}
template <typename T1, typename T2>
inline ostream& operator<<(ostream& os, const map<T1, T2>& v) {
bool first = true;
os << "{";
for (typename map<T1, T2>::const_iterator ii = v.begin(); ii != v.end();
++ii) {
if (!first) os << ",";
os << *ii;
first = false;
}
return os << "}";
}
template <typename T>
bool isPrime(T n) {
T i, lmt = sqrt(n);
for (i = 2; i <= lmt; i++)
if (n % i == 0) return false;
return true;
}
template <typename T>
T gcd(T a, T b) {
if (b == 0) return a;
return gcd(b, a % b);
}
template <typename T>
T BigMod(T b, T p, T m) {
if (p == 0)
return 1 % m;
else if (p & 1)
return ((b % m) * (BigMod(b, p - 1, m) % m)) % m;
else {
T s = BigMod(b, p / 2, m);
return ((s % m) * (s % m)) % m;
}
}
template <typename T>
T power(T b, T p) {
if (p == 0)
return 1;
else if (p & 1)
return b * power(b, p - 1);
else {
T ret = power(b, p / 2);
return ret * ret;
}
}
template <typename T>
T ModInv(T b, T m) {
if (isPrime(b))
return BigMod(b, m - 2, m) % m;
else if (gcd(b, m) == 1)
return BigMod(b, m - 1, m) % m;
}
template <typename T>
T egcd(T a, T b, T& x, T& y) {
T d;
if (a == 0) {
x = 0;
y = 1;
return b;
} else {
T x1, y1;
d = egcd(b % a, a, x1, y1);
x = y1 - (b / a) * x1;
y = x1;
}
return d;
}
int toint(string s) {
int i, j, l;
int num;
l = s.size();
for (i = l - 1, j = 0, num = 0; i >= 0; i--, j++) {
num += (s[i] - 48) * power(10, j);
}
return num;
}
const double pi = acos(-1);
const int inf = (1 << 30);
const long long INF = (1LL << 62) - 1;
const int mod = (int)1e9 + 7;
const long long MOD = (long long)1e9 + 7;
const double EPS = 1e-9;
const int dx8[] = {-1, 0, +1, -1, +1, -1, 0, +1};
const int dy8[] = {+1, +1, +1, 0, 0, -1, -1, -1};
const int dx4[] = {0, -1, +1, 0};
const int dy4[] = {+1, 0, 0, -1};
const int dx2[] = {+1, 0};
const int dy2[] = {0, +1};
const int dxkn[] = {1, -1, 1, -1, 2, -2, -2, 2};
const int dykn[] = {2, 2, -2, -2, 1, 1, -1, -1};
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long a, b, x, y, l1, l2, ans, g;
cin >> a >> b >> x >> y;
g = gcd(x, y);
x = x / g;
y = y / g;
l1 = a / x;
l2 = b / y;
ans = min(l1, l2);
cout << ans << "\n";
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long a, b, x, y;
long long gcd(long long m, long long n) {
long long r;
while (n != 0) {
r = m % n;
m = n;
n = r;
}
return m;
}
int main() {
cin >> a >> b >> x >> y;
long long keep = gcd(x, y);
x /= keep;
y /= keep;
cout << min(a / x, b / y);
}
| ### Prompt
Construct a cpp code solution to the problem outlined:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long a, b, x, y;
long long gcd(long long m, long long n) {
long long r;
while (n != 0) {
r = m % n;
m = n;
n = r;
}
return m;
}
int main() {
cin >> a >> b >> x >> y;
long long keep = gcd(x, y);
x /= keep;
y /= keep;
cout << min(a / x, b / y);
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int N = 0;
int n, k, x, t;
string s;
vector<int> v;
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main() {
long long a, b, c, d;
cin >> a >> b >> c >> d;
long long gd = gcd(c, d);
c /= gd;
d /= gd;
cout << min(a / c, b / d);
return 0;
}
| ### Prompt
Generate a CPP solution to the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 0;
int n, k, x, t;
string s;
vector<int> v;
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main() {
long long a, b, c, d;
cin >> a >> b >> c >> d;
long long gd = gcd(c, d);
c /= gd;
d /= gd;
cout << min(a / c, b / d);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
long long big, small;
big = max(a, b);
small = min(a, b);
if (small == 0) {
return big;
} else {
return gcd(small, big % small);
}
}
int main() {
long long a, b, x, y, factor;
cin >> a >> b >> x >> y;
factor = gcd(x, y);
x /= factor;
y /= factor;
cout << min(a / x, b / y);
}
| ### Prompt
Create a solution in cpp for the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
long long big, small;
big = max(a, b);
small = min(a, b);
if (small == 0) {
return big;
} else {
return gcd(small, big % small);
}
}
int main() {
long long a, b, x, y, factor;
cin >> a >> b >> x >> y;
factor = gcd(x, y);
x /= factor;
y /= factor;
cout << min(a / x, b / y);
}
``` |
#include <bits/stdc++.h>
int main() {
long long a, b, x, y, i, j, l, m, n, o, p;
scanf("%I64d%I64d%I64d%I64d", &a, &b, &x, &y);
if (x > y) {
m = x;
l = y;
} else {
m = y;
l = x;
}
while (l != 0) {
n = m % l;
m = l;
l = n;
}
x /= m;
y /= m;
n = a / x;
o = b / y;
if (n < o)
printf("%I64d\n", n);
else
printf("%I64d", o);
return 0;
}
| ### Prompt
Please provide a cpp coded solution to the problem described below:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
int main() {
long long a, b, x, y, i, j, l, m, n, o, p;
scanf("%I64d%I64d%I64d%I64d", &a, &b, &x, &y);
if (x > y) {
m = x;
l = y;
} else {
m = y;
l = x;
}
while (l != 0) {
n = m % l;
m = l;
l = n;
}
x /= m;
y /= m;
n = a / x;
o = b / y;
if (n < o)
printf("%I64d\n", n);
else
printf("%I64d", o);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using u64 = uint64_t;
using u8 = uint8_t;
using i8 = int8_t;
i64 gcd(i64 a, i64 b) { return (0 == b) ? a : gcd(b, a % b); }
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
i64 a, b, x, y;
cin >> a >> b >> x >> y;
i64 g = gcd(x, y);
x /= g;
y /= g;
cout << min(a / x, b / y);
return 0;
}
| ### Prompt
Your task is to create a CPP solution to the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using u64 = uint64_t;
using u8 = uint8_t;
using i8 = int8_t;
i64 gcd(i64 a, i64 b) { return (0 == b) ? a : gcd(b, a % b); }
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
i64 a, b, x, y;
cin >> a >> b >> x >> y;
i64 g = gcd(x, y);
x /= g;
y /= g;
cout << min(a / x, b / y);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1005;
int a[maxn];
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
int main() {
int i, j;
long long a, b, x, y;
cin >> a >> b >> x >> y;
long long g = gcd(x, y);
x = x / g;
y = y / g;
long long k1 = a / x;
long long k2 = b / y;
cout << min(k1, k2) << endl;
return 0;
}
| ### Prompt
Construct a Cpp code solution to the problem outlined:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1005;
int a[maxn];
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
int main() {
int i, j;
long long a, b, x, y;
cin >> a >> b >> x >> y;
long long g = gcd(x, y);
x = x / g;
y = y / g;
long long k1 = a / x;
long long k2 = b / y;
cout << min(k1, k2) << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long func(long long x, long long y) {
if (y == 0) {
return x;
} else {
return func(y, x % y);
}
}
int main() {
long long a, b, x, y, n, a1, b1;
long long ans;
cin >> a >> b >> x >> y;
n = func(x, y);
a1 = x / n;
b1 = y / n;
ans = min(a / a1, b / b1);
cout << ans;
}
| ### Prompt
Develop a solution in Cpp to the problem described below:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long func(long long x, long long y) {
if (y == 0) {
return x;
} else {
return func(y, x % y);
}
}
int main() {
long long a, b, x, y, n, a1, b1;
long long ans;
cin >> a >> b >> x >> y;
n = func(x, y);
a1 = x / n;
b1 = y / n;
ans = min(a / a1, b / b1);
cout << ans;
}
``` |
#include <bits/stdc++.h>
using namespace std;
void _print(long long t) { cerr << t; }
void _print(int t) { cerr << t; }
void _print(string t) { cerr << t; }
void _print(char t) { cerr << t; }
void _print(long double t) { cerr << t; }
void _print(double t) { cerr << t; }
void _print(unsigned long long t) { cerr << t; }
template <class T, class V>
void _print(pair<T, V> p);
template <class T>
void _print(vector<T> v);
template <class T>
void _print(set<T> v);
template <class T, class V>
void _print(map<T, V> v);
template <class T, class V>
void _print(pair<T, V> p) {
cerr << "{";
_print(p.first);
cerr << ",";
_print(p.second);
cerr << "}";
}
template <class T>
void _print(vector<T> v) {
cerr << "[ ";
for (T i : v) {
_print(i);
cerr << " ";
}
cerr << "]";
}
template <class T>
void _print(set<T> v) {
cerr << "[ ";
for (T i : v) {
_print(i);
cerr << " ";
}
cerr << "]";
}
template <class T>
void _print(multiset<T> v) {
cerr << "[ ";
for (T i : v) {
_print(i);
cerr << " ";
}
cerr << "]";
}
template <class T, class V>
void _print(map<T, V> v) {
cerr << "[ ";
for (auto i : v) {
_print(i);
cerr << " ";
}
cerr << "]";
}
template <class T>
T gcd(T a, T b) {
while (a != 0) {
T temp = a;
a = b % a;
b = temp;
}
return b;
}
template <class T>
T egcd(T a, T b, T &x, T &y) {
T gcd, xt, yt;
if (a == 0) {
gcd = b;
x = 0, y = 1;
} else {
gcd = egcd(b % a, a, xt, yt);
x = yt - (b / a) * xt;
y = xt;
}
return gcd;
}
template <class T>
T expo(T base, T exp, T mod) {
T res = 1;
base = base % mod;
while (exp > 0) {
if (exp & 1) res = (res * base) % mod;
exp = exp >> 1;
base = (base * base) % mod;
}
return res;
}
template <class T>
T modinv(T a, T mod) {
T x, y;
egcd<T>(a, mod, x, y);
while (x < 0) x += mod;
while (x >= mod) x -= mod;
return x;
}
template <class T>
T modinvfermat(T a, T mod) {
return expo<T>(a, mod - 2, mod);
}
template <class T>
bool rev(T a, T b) {
return a > b;
}
template <class T>
long long maxpower(T a, T b) {
long long ans = 0;
while (a > 0 && a % b == 0) {
ans++;
a /= b;
}
return ans;
}
template <class T>
T mceil(T a, T b) {
if (a % b == 0)
return a / b;
else
return a / b + 1;
}
template <class T>
T lcm(T a, T b) {
return (a * b) / gcd<T>(a, b);
}
set<int> s;
vector<bool> vis;
vector<vector<int> > adj;
void dfs(int root) {
vis[root] = true;
;
bool found = false;
for (int i : adj[root]) {
if (s.find(i) != s.end()) {
found = true;
break;
}
}
if (!found) {
s.insert(root);
}
for (int i : adj[root]) {
if (!vis[i]) {
dfs(i);
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long a, b, x, y;
cin >> a >> b >> x >> y;
long long g = gcd<long long>(x, y);
;
long long t1 = x / g, t2 = y / g;
cout << min(a / t1, b / t2);
}
| ### Prompt
Develop a solution in cpp to the problem described below:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
void _print(long long t) { cerr << t; }
void _print(int t) { cerr << t; }
void _print(string t) { cerr << t; }
void _print(char t) { cerr << t; }
void _print(long double t) { cerr << t; }
void _print(double t) { cerr << t; }
void _print(unsigned long long t) { cerr << t; }
template <class T, class V>
void _print(pair<T, V> p);
template <class T>
void _print(vector<T> v);
template <class T>
void _print(set<T> v);
template <class T, class V>
void _print(map<T, V> v);
template <class T, class V>
void _print(pair<T, V> p) {
cerr << "{";
_print(p.first);
cerr << ",";
_print(p.second);
cerr << "}";
}
template <class T>
void _print(vector<T> v) {
cerr << "[ ";
for (T i : v) {
_print(i);
cerr << " ";
}
cerr << "]";
}
template <class T>
void _print(set<T> v) {
cerr << "[ ";
for (T i : v) {
_print(i);
cerr << " ";
}
cerr << "]";
}
template <class T>
void _print(multiset<T> v) {
cerr << "[ ";
for (T i : v) {
_print(i);
cerr << " ";
}
cerr << "]";
}
template <class T, class V>
void _print(map<T, V> v) {
cerr << "[ ";
for (auto i : v) {
_print(i);
cerr << " ";
}
cerr << "]";
}
template <class T>
T gcd(T a, T b) {
while (a != 0) {
T temp = a;
a = b % a;
b = temp;
}
return b;
}
template <class T>
T egcd(T a, T b, T &x, T &y) {
T gcd, xt, yt;
if (a == 0) {
gcd = b;
x = 0, y = 1;
} else {
gcd = egcd(b % a, a, xt, yt);
x = yt - (b / a) * xt;
y = xt;
}
return gcd;
}
template <class T>
T expo(T base, T exp, T mod) {
T res = 1;
base = base % mod;
while (exp > 0) {
if (exp & 1) res = (res * base) % mod;
exp = exp >> 1;
base = (base * base) % mod;
}
return res;
}
template <class T>
T modinv(T a, T mod) {
T x, y;
egcd<T>(a, mod, x, y);
while (x < 0) x += mod;
while (x >= mod) x -= mod;
return x;
}
template <class T>
T modinvfermat(T a, T mod) {
return expo<T>(a, mod - 2, mod);
}
template <class T>
bool rev(T a, T b) {
return a > b;
}
template <class T>
long long maxpower(T a, T b) {
long long ans = 0;
while (a > 0 && a % b == 0) {
ans++;
a /= b;
}
return ans;
}
template <class T>
T mceil(T a, T b) {
if (a % b == 0)
return a / b;
else
return a / b + 1;
}
template <class T>
T lcm(T a, T b) {
return (a * b) / gcd<T>(a, b);
}
set<int> s;
vector<bool> vis;
vector<vector<int> > adj;
void dfs(int root) {
vis[root] = true;
;
bool found = false;
for (int i : adj[root]) {
if (s.find(i) != s.end()) {
found = true;
break;
}
}
if (!found) {
s.insert(root);
}
for (int i : adj[root]) {
if (!vis[i]) {
dfs(i);
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long a, b, x, y;
cin >> a >> b >> x >> y;
long long g = gcd<long long>(x, y);
;
long long t1 = x / g, t2 = y / g;
cout << min(a / t1, b / t2);
}
``` |
#include <bits/stdc++.h>
using namespace std;
int v[1003];
int main() {
long long a, b, x, y, c, d, r, cx, cy;
cin >> a >> b >> x >> y;
cx = x;
cy = y;
while (y > 0) {
r = x % y;
x = y;
y = r;
}
c = cx / x;
d = cy / x;
cout << min(a / c, b / d);
return 0;
}
| ### Prompt
In cpp, your task is to solve the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int v[1003];
int main() {
long long a, b, x, y, c, d, r, cx, cy;
cin >> a >> b >> x >> y;
cx = x;
cy = y;
while (y > 0) {
r = x % y;
x = y;
y = r;
}
c = cx / x;
d = cy / x;
cout << min(a / c, b / d);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long Nod(long long a, long long b) {
while (a && b)
if (a >= b)
a %= b;
else
b %= a;
return a | b;
}
int main() {
long long a, b, x, y, dem, demMin = 1, temp, res = 0, curNod;
cin >> a >> b >> x >> y;
curNod = Nod(x, y);
x /= curNod;
y /= curNod;
res += min(a / x, b / y);
cout << res;
return 0;
}
| ### Prompt
Please formulate a Cpp solution to the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long Nod(long long a, long long b) {
while (a && b)
if (a >= b)
a %= b;
else
b %= a;
return a | b;
}
int main() {
long long a, b, x, y, dem, demMin = 1, temp, res = 0, curNod;
cin >> a >> b >> x >> y;
curNod = Nod(x, y);
x /= curNod;
y /= curNod;
res += min(a / x, b / y);
cout << res;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll X, Y, A, B;
ll ta, tb, tem;
ll gcd(ll a, ll b);
int main() {
scanf("%I64d%I64d%I64d%I64d", &A, &B, &X, &Y);
tem = gcd(X, Y);
X /= tem;
Y /= tem;
ta = B / Y;
tb = A / X;
printf("%I64d\n", min(ta, tb));
}
ll gcd(ll a, ll b) {
if (a < b) swap(a, b);
if (!b)
return a;
else
return gcd(b, a % b);
}
| ### Prompt
In cpp, your task is to solve the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll X, Y, A, B;
ll ta, tb, tem;
ll gcd(ll a, ll b);
int main() {
scanf("%I64d%I64d%I64d%I64d", &A, &B, &X, &Y);
tem = gcd(X, Y);
X /= tem;
Y /= tem;
ta = B / Y;
tb = A / X;
printf("%I64d\n", min(ta, tb));
}
ll gcd(ll a, ll b) {
if (a < b) swap(a, b);
if (!b)
return a;
else
return gcd(b, a % b);
}
``` |
#include <bits/stdc++.h>
using namespace std;
namespace mine {
const int MAX_N = 110000;
int mymin(int x, int y) { return x < y ? x : y; }
int mymax(int x, int y) { return x > y ? x : y; }
long long MOD;
long long qpower(long long x, long long e) {
long long ans = 1;
while (e > 0) {
if (e & 1) ans = ans * x % MOD;
x = x * x % MOD;
e >>= 1;
}
return ans;
}
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
void main() {
long long a, b, x, y;
scanf("%I64d%I64d%I64d%I64d", &a, &b, &x, &y);
long long d = gcd(x, y);
x /= d;
y /= d;
long long t = floor((double)a / x);
long long t2 = floor((double)b / y);
printf("%I64d", t < t2 ? t : t2);
}
}; // namespace mine
int main() { mine::main(); }
| ### Prompt
Please formulate a Cpp solution to the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
namespace mine {
const int MAX_N = 110000;
int mymin(int x, int y) { return x < y ? x : y; }
int mymax(int x, int y) { return x > y ? x : y; }
long long MOD;
long long qpower(long long x, long long e) {
long long ans = 1;
while (e > 0) {
if (e & 1) ans = ans * x % MOD;
x = x * x % MOD;
e >>= 1;
}
return ans;
}
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
void main() {
long long a, b, x, y;
scanf("%I64d%I64d%I64d%I64d", &a, &b, &x, &y);
long long d = gcd(x, y);
x /= d;
y /= d;
long long t = floor((double)a / x);
long long t2 = floor((double)b / y);
printf("%I64d", t < t2 ? t : t2);
}
}; // namespace mine
int main() { mine::main(); }
``` |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (!a) return b;
return gcd(b % a, a);
}
int main() {
long long a, b, x, y;
cin >> a >> b >> x >> y;
long long g = gcd(x, y);
x /= g, y /= g;
cout << min(a / x, b / y);
return 0;
}
| ### Prompt
Please create a solution in CPP to the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (!a) return b;
return gcd(b % a, a);
}
int main() {
long long a, b, x, y;
cin >> a >> b >> x >> y;
long long g = gcd(x, y);
x /= g, y /= g;
cout << min(a / x, b / y);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (b == 0) {
return a;
} else {
return gcd(b, a % b);
}
}
signed main() {
cin.tie(0);
cout << setprecision(10);
long long a, b, x, y;
cin >> a >> b >> x >> y;
long long tmp = gcd(x, y);
x = x / tmp;
y = y / tmp;
cout << min(a / x, b / y) << endl;
}
| ### Prompt
Create a solution in Cpp for the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (b == 0) {
return a;
} else {
return gcd(b, a % b);
}
}
signed main() {
cin.tie(0);
cout << setprecision(10);
long long a, b, x, y;
cin >> a >> b >> x >> y;
long long tmp = gcd(x, y);
x = x / tmp;
y = y / tmp;
cout << min(a / x, b / y) << endl;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long a, b, x, y;
long long gcdxy, Max1, Max2;
long long gcd(long long x, long long y) { return y > 0 ? gcd(y, x % y) : x; }
int main() {
scanf("%lld%lld%lld%lld", &a, &b, &x, &y);
if (x < y) swap(x, y), swap(a, b);
long long z = gcd(x, y);
x /= z;
y /= z;
Max1 = a / x;
Max2 = b / y;
printf("%lld\n", min(Max1, Max2));
return 0;
}
| ### Prompt
Your task is to create a CPP solution to the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long a, b, x, y;
long long gcdxy, Max1, Max2;
long long gcd(long long x, long long y) { return y > 0 ? gcd(y, x % y) : x; }
int main() {
scanf("%lld%lld%lld%lld", &a, &b, &x, &y);
if (x < y) swap(x, y), swap(a, b);
long long z = gcd(x, y);
x /= z;
y /= z;
Max1 = a / x;
Max2 = b / y;
printf("%lld\n", min(Max1, Max2));
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long nzd(long long a, long long b) {
long long m = max(a, b);
long long n = min(a, b);
long long r = 1;
while (r != 0) {
r = m % n;
m = n;
n = r;
}
return m;
}
int main() {
long long a, b, x, y;
scanf("%lld %lld %lld %lld", &a, &b, &x, &y);
long long c = nzd(x, y);
x /= c;
y /= c;
printf("%lld\n", min(a / x, b / y));
return 0;
}
| ### Prompt
Please provide a CPP coded solution to the problem described below:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long nzd(long long a, long long b) {
long long m = max(a, b);
long long n = min(a, b);
long long r = 1;
while (r != 0) {
r = m % n;
m = n;
n = r;
}
return m;
}
int main() {
long long a, b, x, y;
scanf("%lld %lld %lld %lld", &a, &b, &x, &y);
long long c = nzd(x, y);
x /= c;
y /= c;
printf("%lld\n", min(a / x, b / y));
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int a[1005];
long long gcd(long long x, long long y) {
if (y == 0) return x;
return gcd(y, x % y);
}
int main() {
long long n, m, a, b;
cin >> n >> m >> a >> b;
long long gg = gcd(a, b);
a /= gg;
b /= gg;
long long ans = min(n / a, m / b);
cout << ans << endl;
return 0;
}
| ### Prompt
Develop a solution in CPP to the problem described below:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int a[1005];
long long gcd(long long x, long long y) {
if (y == 0) return x;
return gcd(y, x % y);
}
int main() {
long long n, m, a, b;
cin >> n >> m >> a >> b;
long long gg = gcd(a, b);
a /= gg;
b /= gg;
long long ans = min(n / a, m / b);
cout << ans << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
unsigned long long gcd(unsigned long long a, unsigned long long b) {
while (b) {
unsigned long long t = a % b;
a = b;
b = t;
}
return a;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
unsigned long long a, b, x, y;
cin >> a >> b >> x >> y;
unsigned long long g = gcd(x, y);
x /= g;
y /= g;
cout << min(a / x, b / y) << '\n';
return 0;
}
| ### Prompt
Your challenge is to write a CPP solution to the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
unsigned long long gcd(unsigned long long a, unsigned long long b) {
while (b) {
unsigned long long t = a % b;
a = b;
b = t;
}
return a;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
unsigned long long a, b, x, y;
cin >> a >> b >> x >> y;
unsigned long long g = gcd(x, y);
x /= g;
y /= g;
cout << min(a / x, b / y) << '\n';
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long x, long long y) {
long long t;
while (y) {
t = x % y;
x = y;
y = t;
}
return x;
}
int main() {
long long a, b, x, y, ct = 0, m, j = 1, w = 1;
scanf("%lld%lld%lld%lld", &a, &b, &x, &y);
m = gcd(x, y);
x = x / m;
y = y / m;
ct = min(a / x, b / y);
printf("%lld\n", ct);
}
| ### Prompt
Please formulate a cpp solution to the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long x, long long y) {
long long t;
while (y) {
t = x % y;
x = y;
y = t;
}
return x;
}
int main() {
long long a, b, x, y, ct = 0, m, j = 1, w = 1;
scanf("%lld%lld%lld%lld", &a, &b, &x, &y);
m = gcd(x, y);
x = x / m;
y = y / m;
ct = min(a / x, b / y);
printf("%lld\n", ct);
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long a, b, x, y, c, d;
long long gcd(long long x, long long y) {
if (!y) {
return x;
} else {
return gcd(y, x % y);
}
}
int main() {
cin >> a >> b >> x >> y;
long long g = gcd(x, y);
x /= g;
y /= g;
c = a / x;
d = b / y;
cout << min(c, d) << endl;
return 0;
}
| ### Prompt
Your task is to create a Cpp solution to the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long a, b, x, y, c, d;
long long gcd(long long x, long long y) {
if (!y) {
return x;
} else {
return gcd(y, x % y);
}
}
int main() {
cin >> a >> b >> x >> y;
long long g = gcd(x, y);
x /= g;
y /= g;
c = a / x;
d = b / y;
cout << min(c, d) << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long x, long long y) {
if (y == 0)
return x;
else
return gcd(y, x % y);
}
int main() {
long long res, res1, res2;
long long x1, y1, a, b;
cin >> x1 >> y1 >> a >> b;
long long tt = gcd(a, b);
a = a / tt;
b = b / tt;
res1 = x1 / a;
res2 = y1 / b;
res = min(res2, res1);
cout << res << endl;
}
| ### Prompt
Please formulate a cpp solution to the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long x, long long y) {
if (y == 0)
return x;
else
return gcd(y, x % y);
}
int main() {
long long res, res1, res2;
long long x1, y1, a, b;
cin >> x1 >> y1 >> a >> b;
long long tt = gcd(a, b);
a = a / tt;
b = b / tt;
res1 = x1 / a;
res2 = y1 / b;
res = min(res2, res1);
cout << res << endl;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long x, long long y) { return x == 0 ? y : gcd(y % x, x); }
int main() {
long long a, b, x, y;
long long ans = 0;
cin >> a >> b >> x >> y;
long long t = gcd(x, y);
x /= t, y /= t;
ans = min(a / x, b / y);
cout << ans << endl;
return 0;
}
| ### Prompt
Your task is to create a CPP solution to the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long x, long long y) { return x == 0 ? y : gcd(y % x, x); }
int main() {
long long a, b, x, y;
long long ans = 0;
cin >> a >> b >> x >> y;
long long t = gcd(x, y);
x /= t, y /= t;
ans = min(a / x, b / y);
cout << ans << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
unsigned long long int gcd(unsigned long long int a, unsigned long long int b) {
if (a == 0) return b;
return gcd(b % a, a);
}
int main() {
unsigned long long int a, b, x, y;
cin >> a >> b >> x >> y;
cout << min(a / (x / gcd(x, y)), b / (y / gcd(x, y))) << endl;
return 0;
}
| ### Prompt
Your task is to create a cpp solution to the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
unsigned long long int gcd(unsigned long long int a, unsigned long long int b) {
if (a == 0) return b;
return gcd(b % a, a);
}
int main() {
unsigned long long int a, b, x, y;
cin >> a >> b >> x >> y;
cout << min(a / (x / gcd(x, y)), b / (y / gcd(x, y))) << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using ll = long long;
ll gcd(ll a, ll b) {
while (b) {
a %= b;
std::swap(a, b);
}
return a;
}
int32_t main() {
ll a, b, x, y;
scanf("%lld%lld%lld%lld", &a, &b, &x, &y);
ll d = gcd(x, y);
x /= d;
y /= d;
ll maxa = a / x;
ll maxb = b / y;
printf("%lld\n", std::min(maxa, maxb));
return 0;
}
| ### Prompt
Create a solution in Cpp for the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using ll = long long;
ll gcd(ll a, ll b) {
while (b) {
a %= b;
std::swap(a, b);
}
return a;
}
int32_t main() {
ll a, b, x, y;
scanf("%lld%lld%lld%lld", &a, &b, &x, &y);
ll d = gcd(x, y);
x /= d;
y /= d;
ll maxa = a / x;
ll maxb = b / y;
printf("%lld\n", std::min(maxa, maxb));
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int gcd(int q, int w) {
if (q == 0)
return w;
else
return gcd(w % q, q);
}
int main() {
long long int w, h, x, y, p;
cin >> w >> h >> x >> y;
p = gcd(x, y);
x = x / p;
y = y / p;
cout << min(w / x, h / y);
}
| ### Prompt
Create a solution in cpp for the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int gcd(int q, int w) {
if (q == 0)
return w;
else
return gcd(w % q, q);
}
int main() {
long long int w, h, x, y, p;
cin >> w >> h >> x >> y;
p = gcd(x, y);
x = x / p;
y = y / p;
cout << min(w / x, h / y);
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
long long r = a % b;
while (r != 0) {
a = b;
b = r;
r = a % b;
}
return b;
}
int main() {
long long a, b, x, y, mini;
cin >> a >> b >> x >> y;
long long div = gcd(x, y);
x = x / div;
y = y / div;
if (a / x > b / y)
mini = b / y;
else
mini = a / x;
cout << mini;
return 0;
}
| ### Prompt
Please create a solution in Cpp to the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
long long r = a % b;
while (r != 0) {
a = b;
b = r;
r = a % b;
}
return b;
}
int main() {
long long a, b, x, y, mini;
cin >> a >> b >> x >> y;
long long div = gcd(x, y);
x = x / div;
y = y / div;
if (a / x > b / y)
mini = b / y;
else
mini = a / x;
cout << mini;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long a, b, c, d, x, y, xtemp, ytemp, temp, n, i, j;
int main() {
cin >> a >> b >> x >> y;
xtemp = x;
ytemp = y;
if (xtemp < ytemp) {
temp = xtemp;
xtemp = ytemp;
ytemp = temp;
}
while ((xtemp % ytemp) != 0) {
temp = ytemp;
ytemp = (long long)(xtemp % ytemp);
xtemp = temp;
}
x = (long long)(x / ytemp);
y = (long long)(y / ytemp);
i = (long long)(a / x);
j = (long long)(b / y);
if (i > j)
cout << j;
else
cout << i;
return 0;
}
| ### Prompt
Create a solution in Cpp for the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long a, b, c, d, x, y, xtemp, ytemp, temp, n, i, j;
int main() {
cin >> a >> b >> x >> y;
xtemp = x;
ytemp = y;
if (xtemp < ytemp) {
temp = xtemp;
xtemp = ytemp;
ytemp = temp;
}
while ((xtemp % ytemp) != 0) {
temp = ytemp;
ytemp = (long long)(xtemp % ytemp);
xtemp = temp;
}
x = (long long)(x / ytemp);
y = (long long)(y / ytemp);
i = (long long)(a / x);
j = (long long)(b / y);
if (i > j)
cout << j;
else
cout << i;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long a, b, x, y;
long long gcd(long long a, long long b) {
long long t;
while (b > 0) {
t = a % b;
a = b;
b = t;
}
return (a);
}
void input() {
cin >> a >> b >> x >> y;
long long u = gcd(x, y);
x /= u;
y /= u;
}
void output() { cout << min(a / x, b / y); }
int main() {
input();
output();
}
| ### Prompt
Your challenge is to write a cpp solution to the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long a, b, x, y;
long long gcd(long long a, long long b) {
long long t;
while (b > 0) {
t = a % b;
a = b;
b = t;
}
return (a);
}
void input() {
cin >> a >> b >> x >> y;
long long u = gcd(x, y);
x /= u;
y /= u;
}
void output() { cout << min(a / x, b / y); }
int main() {
input();
output();
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main() {
long long a, b, x, y, l, m;
cin >> a >> b >> x >> y;
l = x / gcd(x, y);
m = y / gcd(x, y);
cout << min(a / l, b / m) << endl;
return 0;
}
| ### Prompt
Your challenge is to write a cpp solution to the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main() {
long long a, b, x, y, l, m;
cin >> a >> b >> x >> y;
l = x / gcd(x, y);
m = y / gcd(x, y);
cout << min(a / l, b / m) << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
if (a == 0) return b;
return gcd(b % a, a);
}
long long int lcm(long long int x, long long int y) {
return ((x * y) / gcd(x, y));
}
bool prime(long long int n) {
if (n == 1) return false;
if (n == 2) return true;
long long int k = sqrt(n) + 1;
for (int i = 2; i < k; i++)
if (n % i == 0) return false;
return true;
}
long long int modpow(long long int x, long long int y, long long int p) {
long long int res = 1;
x = x % p;
while (y > 0) {
if (y & 1) res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
long long int power(long long int x, long long int n) {
if (n == 0) return 1;
if (n % 2 == 0)
return power(x * x, n / 2);
else
return x * power(x, n - 1);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int a, b, x, y;
cin >> a >> b >> x >> y;
long long int c = 0;
long long int k = gcd(x, y);
x /= k;
y /= k;
c = min((a / x), (b / y));
cout << c;
return 0;
}
| ### Prompt
Generate a CPP solution to the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
if (a == 0) return b;
return gcd(b % a, a);
}
long long int lcm(long long int x, long long int y) {
return ((x * y) / gcd(x, y));
}
bool prime(long long int n) {
if (n == 1) return false;
if (n == 2) return true;
long long int k = sqrt(n) + 1;
for (int i = 2; i < k; i++)
if (n % i == 0) return false;
return true;
}
long long int modpow(long long int x, long long int y, long long int p) {
long long int res = 1;
x = x % p;
while (y > 0) {
if (y & 1) res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
long long int power(long long int x, long long int n) {
if (n == 0) return 1;
if (n % 2 == 0)
return power(x * x, n / 2);
else
return x * power(x, n - 1);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int a, b, x, y;
cin >> a >> b >> x >> y;
long long int c = 0;
long long int k = gcd(x, y);
x /= k;
y /= k;
c = min((a / x), (b / y));
cout << c;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long a, b, x, y;
long long gcd(long long ai, long long bi) {
if (bi == 0) return ai;
return gcd(bi, ai % bi);
}
int main() {
cin >> a >> b >> x >> y;
long long d = gcd(x, y);
x = x / d;
y = y / d;
cout << min(a / x, b / y);
}
| ### Prompt
Please formulate a cpp solution to the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long a, b, x, y;
long long gcd(long long ai, long long bi) {
if (bi == 0) return ai;
return gcd(bi, ai % bi);
}
int main() {
cin >> a >> b >> x >> y;
long long d = gcd(x, y);
x = x / d;
y = y / d;
cout << min(a / x, b / y);
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (a == b) {
return a;
}
if (a == 0) {
return b;
}
if (b == 0) {
return a;
}
if (a > b) {
return gcd(a % b, b);
} else {
return gcd(a, b % a);
}
}
int main() {
long long a, b, x, y;
cin >> a >> b >> x >> y;
long long k = gcd(x, y);
x /= k;
y /= k;
cout << min(a / x, b / y) << endl;
}
| ### Prompt
Generate a Cpp solution to the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (a == b) {
return a;
}
if (a == 0) {
return b;
}
if (b == 0) {
return a;
}
if (a > b) {
return gcd(a % b, b);
} else {
return gcd(a, b % a);
}
}
int main() {
long long a, b, x, y;
cin >> a >> b >> x >> y;
long long k = gcd(x, y);
x /= k;
y /= k;
cout << min(a / x, b / y) << endl;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int dir[4][2] = {1, 0, -1, 0, 0, 1, 0, -1};
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
const double PI = acos(-1);
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + 11;
long long a, b, x, y, ans = 0;
int main(int argc, char const *argv[]) {
cin >> a >> b >> x >> y;
long long t = gcd(x, y);
x /= t;
y /= t;
cout << min(a / x, b / y) << endl;
return 0;
}
| ### Prompt
Your challenge is to write a cpp solution to the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int dir[4][2] = {1, 0, -1, 0, 0, 1, 0, -1};
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
const double PI = acos(-1);
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + 11;
long long a, b, x, y, ans = 0;
int main(int argc, char const *argv[]) {
cin >> a >> b >> x >> y;
long long t = gcd(x, y);
x /= t;
y /= t;
cout << min(a / x, b / y) << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
void fast() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
long long gcd(long long a, long long b) {
if (a == 0)
return b;
else
return (gcd(b % a, a));
}
int main() {
fast();
long long a, b, c, d;
cin >> a >> b >> c >> d;
long long f = gcd(c, d);
c = c / f;
d = d / f;
long long p = a / c;
long long k = b / d;
if (k < p) p = k;
cout << p;
}
| ### Prompt
Please formulate a Cpp solution to the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
void fast() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
long long gcd(long long a, long long b) {
if (a == 0)
return b;
else
return (gcd(b % a, a));
}
int main() {
fast();
long long a, b, c, d;
cin >> a >> b >> c >> d;
long long f = gcd(c, d);
c = c / f;
d = d / f;
long long p = a / c;
long long k = b / d;
if (k < p) p = k;
cout << p;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main() {
long long a, b, x, y;
cin >> a >> b >> x >> y;
long long g = gcd(x, y);
x = x / g;
y = y / g;
long long na = a / x, nb = b / y;
long long n = min(na, nb);
cout << n << endl;
return 0;
}
| ### Prompt
Create a solution in Cpp for the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main() {
long long a, b, x, y;
cin >> a >> b >> x >> y;
long long g = gcd(x, y);
x = x / g;
y = y / g;
long long na = a / x, nb = b / y;
long long n = min(na, nb);
cout << n << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long int i, j, k, sum = 0, ans = 0, n;
void fastio() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
long long int gcd(long long int a, long long int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
void solve() {
cin >> n >> i >> j >> k;
long long int v = gcd(j, k);
j = j / v;
k = k / v;
long long int p = n / j;
long long int q = i / k;
cout << min(p, q);
}
int main() {
fastio();
solve();
return 0;
}
| ### Prompt
Your task is to create a cpp solution to the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long int i, j, k, sum = 0, ans = 0, n;
void fastio() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
long long int gcd(long long int a, long long int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
void solve() {
cin >> n >> i >> j >> k;
long long int v = gcd(j, k);
j = j / v;
k = k / v;
long long int p = n / j;
long long int q = i / k;
cout << min(p, q);
}
int main() {
fastio();
solve();
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long nzd(long long a, long long b) {
if (b == 0)
return a;
else
return nzd(b, a % b);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cout << fixed << setprecision(10);
long long a, b, x, y;
cin >> a >> b >> x >> y;
long long nzdd = nzd(x, y);
x = x / nzdd;
y = y / nzdd;
long long r1, r2;
r1 = a / x;
r2 = b / y;
cout << min(r1, r2);
}
| ### Prompt
Please formulate a cpp solution to the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long nzd(long long a, long long b) {
if (b == 0)
return a;
else
return nzd(b, a % b);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cout << fixed << setprecision(10);
long long a, b, x, y;
cin >> a >> b >> x >> y;
long long nzdd = nzd(x, y);
x = x / nzdd;
y = y / nzdd;
long long r1, r2;
r1 = a / x;
r2 = b / y;
cout << min(r1, r2);
}
``` |
#include <bits/stdc++.h>
using namespace std;
unsigned long long a, b, x, y;
unsigned long long gcd(unsigned long long a, unsigned long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main() {
cin >> a >> b >> x >> y;
unsigned long long z = gcd(x, y);
x /= z;
y /= z;
cout << min(a / x, b / y);
return 0;
}
| ### Prompt
Your task is to create a CPP solution to the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
unsigned long long a, b, x, y;
unsigned long long gcd(unsigned long long a, unsigned long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main() {
cin >> a >> b >> x >> y;
unsigned long long z = gcd(x, y);
x /= z;
y /= z;
cout << min(a / x, b / y);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int u, long long int v) {
if (u == 0)
return v;
else
return gcd(v % u, u);
}
int main() {
long long int a, b, x, y;
cin >> a >> b >> x >> y;
long long int s;
if (x > y)
s = gcd(x, y);
else
s = gcd(y, x);
x = x / s;
y = y / s;
long long int o, p;
o = a / x;
p = b / y;
if (o > p) {
cout << p << "\n";
} else {
cout << o << "\n";
}
}
| ### Prompt
In Cpp, your task is to solve the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int u, long long int v) {
if (u == 0)
return v;
else
return gcd(v % u, u);
}
int main() {
long long int a, b, x, y;
cin >> a >> b >> x >> y;
long long int s;
if (x > y)
s = gcd(x, y);
else
s = gcd(y, x);
x = x / s;
y = y / s;
long long int o, p;
o = a / x;
p = b / y;
if (o > p) {
cout << p << "\n";
} else {
cout << o << "\n";
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (!b) return a;
return gcd(b, a % b);
}
int main() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
long long a, b, x, y;
cin >> a >> b >> x >> y;
long long g = gcd(x, y);
x /= g;
y /= g;
cout << min(a / x, b / y) << endl;
return 0;
}
| ### Prompt
Your task is to create a cpp solution to the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (!b) return a;
return gcd(b, a % b);
}
int main() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
long long a, b, x, y;
cin >> a >> b >> x >> y;
long long g = gcd(x, y);
x /= g;
y /= g;
cout << min(a / x, b / y) << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long a, b, x, y;
long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }
int main() {
scanf("%I64d%I64d%I64d%I64d", &a, &b, &x, &y);
long long g = gcd(x, y);
x /= g, y /= g;
printf("%I64d\n", min(a / x, b / y));
return 0;
}
| ### Prompt
Your task is to create a cpp solution to the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long a, b, x, y;
long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }
int main() {
scanf("%I64d%I64d%I64d%I64d", &a, &b, &x, &y);
long long g = gcd(x, y);
x /= g, y /= g;
printf("%I64d\n", min(a / x, b / y));
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (b == 0) {
return a;
}
gcd(b, a % b);
}
int main() {
long long t = 1;
while (t--) {
long long a, b, x, y;
cin >> a >> b >> x >> y;
long long f = gcd(x, y);
x = x / f;
y = y / f;
x = (a / x);
y = (b / y);
cout << min(x, y) << endl;
}
}
| ### Prompt
Your task is to create a CPP solution to the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (b == 0) {
return a;
}
gcd(b, a % b);
}
int main() {
long long t = 1;
while (t--) {
long long a, b, x, y;
cin >> a >> b >> x >> y;
long long f = gcd(x, y);
x = x / f;
y = y / f;
x = (a / x);
y = (b / y);
cout << min(x, y) << endl;
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T a, T b) {
if (b > a) swap(a, b);
while (b != 0) {
T r = a % b;
a = b;
b = r;
}
return a;
}
int main() {
long long a, b, x, y;
cin >> a >> b >> x >> y;
long long g = gcd(x, y);
x /= g;
y /= g;
long long n = min(a / x, b / y);
cout << n;
}
| ### Prompt
Your task is to create a Cpp solution to the following problem:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w β€ a), (h β€ b) and (w/h = x/y).
In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers a, b, x, y (1 β€ a, b, x, y β€ 10^{18}) β the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer β the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
Note
In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9).
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: (3, 2).
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T a, T b) {
if (b > a) swap(a, b);
while (b != 0) {
T r = a % b;
a = b;
b = r;
}
return a;
}
int main() {
long long a, b, x, y;
cin >> a >> b >> x >> y;
long long g = gcd(x, y);
x /= g;
y /= g;
long long n = min(a / x, b / y);
cout << n;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int a, b, c, res;
int main() {
cin >> a >> b >> c;
vector<int> v = {a, b, c};
sort(v.begin(), v.end());
while (v[0] + v[1] <= v[2]) v[0]++, res++;
cout << res << endl;
return 0;
}
| ### Prompt
Your task is to create a CPP solution to the following problem:
Masha has three sticks of length a, b and c centimeters respectively. In one minute Masha can pick one arbitrary stick and increase its length by one centimeter. She is not allowed to break sticks.
What is the minimum number of minutes she needs to spend increasing the stick's length in order to be able to assemble a triangle of positive area. Sticks should be used as triangle's sides (one stick for one side) and their endpoints should be located at triangle's vertices.
Input
The only line contains tree integers a, b and c (1 β€ a, b, c β€ 100) β the lengths of sticks Masha possesses.
Output
Print a single integer β the minimum number of minutes that Masha needs to spend in order to be able to make the triangle of positive area from her sticks.
Examples
Input
3 4 5
Output
0
Input
2 5 3
Output
1
Input
100 10 10
Output
81
Note
In the first example, Masha can make a triangle from the sticks without increasing the length of any of them.
In the second example, Masha can't make a triangle of positive area from the sticks she has at the beginning, but she can spend one minute to increase the length 2 centimeter stick by one and after that form a triangle with sides 3, 3 and 5 centimeters.
In the third example, Masha can take 33 minutes to increase one of the 10 centimeters sticks by 33 centimeters, and after that take 48 minutes to increase another 10 centimeters stick by 48 centimeters. This way she can form a triangle with lengths 43, 58 and 100 centimeters in 81 minutes. One can show that it is impossible to get a valid triangle faster.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int a, b, c, res;
int main() {
cin >> a >> b >> c;
vector<int> v = {a, b, c};
sort(v.begin(), v.end());
while (v[0] + v[1] <= v[2]) v[0]++, res++;
cout << res << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int arr[3];
cin >> arr[0] >> arr[1] >> arr[2];
sort(arr, arr + 3);
cout << max(0, arr[2] - (arr[0] + arr[1] - 1)) << "\n";
}
| ### Prompt
Develop a solution in Cpp to the problem described below:
Masha has three sticks of length a, b and c centimeters respectively. In one minute Masha can pick one arbitrary stick and increase its length by one centimeter. She is not allowed to break sticks.
What is the minimum number of minutes she needs to spend increasing the stick's length in order to be able to assemble a triangle of positive area. Sticks should be used as triangle's sides (one stick for one side) and their endpoints should be located at triangle's vertices.
Input
The only line contains tree integers a, b and c (1 β€ a, b, c β€ 100) β the lengths of sticks Masha possesses.
Output
Print a single integer β the minimum number of minutes that Masha needs to spend in order to be able to make the triangle of positive area from her sticks.
Examples
Input
3 4 5
Output
0
Input
2 5 3
Output
1
Input
100 10 10
Output
81
Note
In the first example, Masha can make a triangle from the sticks without increasing the length of any of them.
In the second example, Masha can't make a triangle of positive area from the sticks she has at the beginning, but she can spend one minute to increase the length 2 centimeter stick by one and after that form a triangle with sides 3, 3 and 5 centimeters.
In the third example, Masha can take 33 minutes to increase one of the 10 centimeters sticks by 33 centimeters, and after that take 48 minutes to increase another 10 centimeters stick by 48 centimeters. This way she can form a triangle with lengths 43, 58 and 100 centimeters in 81 minutes. One can show that it is impossible to get a valid triangle faster.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int arr[3];
cin >> arr[0] >> arr[1] >> arr[2];
sort(arr, arr + 3);
cout << max(0, arr[2] - (arr[0] + arr[1] - 1)) << "\n";
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int p[3];
int x;
for (int i = 0; i < 3; i++) {
cin >> p[i];
}
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 3; j++) {
if (p[i] < p[j]) {
x = p[i];
p[i] = p[j];
p[j] = x;
}
}
}
if (p[0] + p[1] > p[2] && p[0] + p[2] > p[1] && p[2] + p[1] > p[0]) {
cout << "0";
} else {
cout << p[0] - p[1] - p[2] + 1;
}
return 0;
}
| ### Prompt
Your challenge is to write a Cpp solution to the following problem:
Masha has three sticks of length a, b and c centimeters respectively. In one minute Masha can pick one arbitrary stick and increase its length by one centimeter. She is not allowed to break sticks.
What is the minimum number of minutes she needs to spend increasing the stick's length in order to be able to assemble a triangle of positive area. Sticks should be used as triangle's sides (one stick for one side) and their endpoints should be located at triangle's vertices.
Input
The only line contains tree integers a, b and c (1 β€ a, b, c β€ 100) β the lengths of sticks Masha possesses.
Output
Print a single integer β the minimum number of minutes that Masha needs to spend in order to be able to make the triangle of positive area from her sticks.
Examples
Input
3 4 5
Output
0
Input
2 5 3
Output
1
Input
100 10 10
Output
81
Note
In the first example, Masha can make a triangle from the sticks without increasing the length of any of them.
In the second example, Masha can't make a triangle of positive area from the sticks she has at the beginning, but she can spend one minute to increase the length 2 centimeter stick by one and after that form a triangle with sides 3, 3 and 5 centimeters.
In the third example, Masha can take 33 minutes to increase one of the 10 centimeters sticks by 33 centimeters, and after that take 48 minutes to increase another 10 centimeters stick by 48 centimeters. This way she can form a triangle with lengths 43, 58 and 100 centimeters in 81 minutes. One can show that it is impossible to get a valid triangle faster.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int p[3];
int x;
for (int i = 0; i < 3; i++) {
cin >> p[i];
}
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 3; j++) {
if (p[i] < p[j]) {
x = p[i];
p[i] = p[j];
p[j] = x;
}
}
}
if (p[0] + p[1] > p[2] && p[0] + p[2] > p[1] && p[2] + p[1] > p[0]) {
cout << "0";
} else {
cout << p[0] - p[1] - p[2] + 1;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[3];
int i;
for (i = 0; i < 3; i++) {
cin >> a[i];
}
sort(a, a + 3);
if (a[0] + a[1] > a[2]) {
cout << "0" << endl;
} else {
int res = a[2] - (a[0] + a[1]) + 1;
cout << res << endl;
}
return 0;
}
| ### Prompt
Create a solution in Cpp for the following problem:
Masha has three sticks of length a, b and c centimeters respectively. In one minute Masha can pick one arbitrary stick and increase its length by one centimeter. She is not allowed to break sticks.
What is the minimum number of minutes she needs to spend increasing the stick's length in order to be able to assemble a triangle of positive area. Sticks should be used as triangle's sides (one stick for one side) and their endpoints should be located at triangle's vertices.
Input
The only line contains tree integers a, b and c (1 β€ a, b, c β€ 100) β the lengths of sticks Masha possesses.
Output
Print a single integer β the minimum number of minutes that Masha needs to spend in order to be able to make the triangle of positive area from her sticks.
Examples
Input
3 4 5
Output
0
Input
2 5 3
Output
1
Input
100 10 10
Output
81
Note
In the first example, Masha can make a triangle from the sticks without increasing the length of any of them.
In the second example, Masha can't make a triangle of positive area from the sticks she has at the beginning, but she can spend one minute to increase the length 2 centimeter stick by one and after that form a triangle with sides 3, 3 and 5 centimeters.
In the third example, Masha can take 33 minutes to increase one of the 10 centimeters sticks by 33 centimeters, and after that take 48 minutes to increase another 10 centimeters stick by 48 centimeters. This way she can form a triangle with lengths 43, 58 and 100 centimeters in 81 minutes. One can show that it is impossible to get a valid triangle faster.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[3];
int i;
for (i = 0; i < 3; i++) {
cin >> a[i];
}
sort(a, a + 3);
if (a[0] + a[1] > a[2]) {
cout << "0" << endl;
} else {
int res = a[2] - (a[0] + a[1]) + 1;
cout << res << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
bool check(int a, int b, int c);
int main() {
int i, j, a, b, c, minn;
scanf("%d %d %d", &a, &b, &c);
i = 0;
while (!check(a, b, c)) {
i++;
minn = min(a, b);
minn = min(minn, c);
if (minn == a) {
check(a++, b, c);
continue;
}
if (minn == b) {
check(a, b++, c);
continue;
}
if (minn == c) {
check(a, b, c++);
continue;
}
}
printf("%d\n", i);
return 0;
}
bool check(int a, int b, int c) {
if (a + b > c && b + c > a && c + a > b) {
return true;
}
return false;
}
| ### Prompt
In CPP, your task is to solve the following problem:
Masha has three sticks of length a, b and c centimeters respectively. In one minute Masha can pick one arbitrary stick and increase its length by one centimeter. She is not allowed to break sticks.
What is the minimum number of minutes she needs to spend increasing the stick's length in order to be able to assemble a triangle of positive area. Sticks should be used as triangle's sides (one stick for one side) and their endpoints should be located at triangle's vertices.
Input
The only line contains tree integers a, b and c (1 β€ a, b, c β€ 100) β the lengths of sticks Masha possesses.
Output
Print a single integer β the minimum number of minutes that Masha needs to spend in order to be able to make the triangle of positive area from her sticks.
Examples
Input
3 4 5
Output
0
Input
2 5 3
Output
1
Input
100 10 10
Output
81
Note
In the first example, Masha can make a triangle from the sticks without increasing the length of any of them.
In the second example, Masha can't make a triangle of positive area from the sticks she has at the beginning, but she can spend one minute to increase the length 2 centimeter stick by one and after that form a triangle with sides 3, 3 and 5 centimeters.
In the third example, Masha can take 33 minutes to increase one of the 10 centimeters sticks by 33 centimeters, and after that take 48 minutes to increase another 10 centimeters stick by 48 centimeters. This way she can form a triangle with lengths 43, 58 and 100 centimeters in 81 minutes. One can show that it is impossible to get a valid triangle faster.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
bool check(int a, int b, int c);
int main() {
int i, j, a, b, c, minn;
scanf("%d %d %d", &a, &b, &c);
i = 0;
while (!check(a, b, c)) {
i++;
minn = min(a, b);
minn = min(minn, c);
if (minn == a) {
check(a++, b, c);
continue;
}
if (minn == b) {
check(a, b++, c);
continue;
}
if (minn == c) {
check(a, b, c++);
continue;
}
}
printf("%d\n", i);
return 0;
}
bool check(int a, int b, int c) {
if (a + b > c && b + c > a && c + a > b) {
return true;
}
return false;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[3];
cin >> a[0] >> a[1] >> a[2];
sort(a, a + 3);
int ans = 0;
while (a[0] + a[1] <= a[2]) {
ans++;
a[0]++;
}
cout << ans << "\n";
return 0;
}
| ### Prompt
Your task is to create a CPP solution to the following problem:
Masha has three sticks of length a, b and c centimeters respectively. In one minute Masha can pick one arbitrary stick and increase its length by one centimeter. She is not allowed to break sticks.
What is the minimum number of minutes she needs to spend increasing the stick's length in order to be able to assemble a triangle of positive area. Sticks should be used as triangle's sides (one stick for one side) and their endpoints should be located at triangle's vertices.
Input
The only line contains tree integers a, b and c (1 β€ a, b, c β€ 100) β the lengths of sticks Masha possesses.
Output
Print a single integer β the minimum number of minutes that Masha needs to spend in order to be able to make the triangle of positive area from her sticks.
Examples
Input
3 4 5
Output
0
Input
2 5 3
Output
1
Input
100 10 10
Output
81
Note
In the first example, Masha can make a triangle from the sticks without increasing the length of any of them.
In the second example, Masha can't make a triangle of positive area from the sticks she has at the beginning, but she can spend one minute to increase the length 2 centimeter stick by one and after that form a triangle with sides 3, 3 and 5 centimeters.
In the third example, Masha can take 33 minutes to increase one of the 10 centimeters sticks by 33 centimeters, and after that take 48 minutes to increase another 10 centimeters stick by 48 centimeters. This way she can form a triangle with lengths 43, 58 and 100 centimeters in 81 minutes. One can show that it is impossible to get a valid triangle faster.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[3];
cin >> a[0] >> a[1] >> a[2];
sort(a, a + 3);
int ans = 0;
while (a[0] + a[1] <= a[2]) {
ans++;
a[0]++;
}
cout << ans << "\n";
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int a[3];
int main() {
cin >> a[0] >> a[1] >> a[2];
sort(a, a + 3);
cout << max(0, a[2] - a[1] - a[0] + 1);
return 0;
}
| ### Prompt
Your challenge is to write a Cpp solution to the following problem:
Masha has three sticks of length a, b and c centimeters respectively. In one minute Masha can pick one arbitrary stick and increase its length by one centimeter. She is not allowed to break sticks.
What is the minimum number of minutes she needs to spend increasing the stick's length in order to be able to assemble a triangle of positive area. Sticks should be used as triangle's sides (one stick for one side) and their endpoints should be located at triangle's vertices.
Input
The only line contains tree integers a, b and c (1 β€ a, b, c β€ 100) β the lengths of sticks Masha possesses.
Output
Print a single integer β the minimum number of minutes that Masha needs to spend in order to be able to make the triangle of positive area from her sticks.
Examples
Input
3 4 5
Output
0
Input
2 5 3
Output
1
Input
100 10 10
Output
81
Note
In the first example, Masha can make a triangle from the sticks without increasing the length of any of them.
In the second example, Masha can't make a triangle of positive area from the sticks she has at the beginning, but she can spend one minute to increase the length 2 centimeter stick by one and after that form a triangle with sides 3, 3 and 5 centimeters.
In the third example, Masha can take 33 minutes to increase one of the 10 centimeters sticks by 33 centimeters, and after that take 48 minutes to increase another 10 centimeters stick by 48 centimeters. This way she can form a triangle with lengths 43, 58 and 100 centimeters in 81 minutes. One can show that it is impossible to get a valid triangle faster.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int a[3];
int main() {
cin >> a[0] >> a[1] >> a[2];
sort(a, a + 3);
cout << max(0, a[2] - a[1] - a[0] + 1);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
short a, b, c;
cin >> a >> b >> c;
short u = 0;
if (a + b <= c) u += c - a - b + 1;
if (a + c <= b) u += b - a - c + 1;
if (b + c <= a) u += a - b - c + 1;
cout << u;
return 0;
}
| ### Prompt
Your task is to create a Cpp solution to the following problem:
Masha has three sticks of length a, b and c centimeters respectively. In one minute Masha can pick one arbitrary stick and increase its length by one centimeter. She is not allowed to break sticks.
What is the minimum number of minutes she needs to spend increasing the stick's length in order to be able to assemble a triangle of positive area. Sticks should be used as triangle's sides (one stick for one side) and their endpoints should be located at triangle's vertices.
Input
The only line contains tree integers a, b and c (1 β€ a, b, c β€ 100) β the lengths of sticks Masha possesses.
Output
Print a single integer β the minimum number of minutes that Masha needs to spend in order to be able to make the triangle of positive area from her sticks.
Examples
Input
3 4 5
Output
0
Input
2 5 3
Output
1
Input
100 10 10
Output
81
Note
In the first example, Masha can make a triangle from the sticks without increasing the length of any of them.
In the second example, Masha can't make a triangle of positive area from the sticks she has at the beginning, but she can spend one minute to increase the length 2 centimeter stick by one and after that form a triangle with sides 3, 3 and 5 centimeters.
In the third example, Masha can take 33 minutes to increase one of the 10 centimeters sticks by 33 centimeters, and after that take 48 minutes to increase another 10 centimeters stick by 48 centimeters. This way she can form a triangle with lengths 43, 58 and 100 centimeters in 81 minutes. One can show that it is impossible to get a valid triangle faster.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
short a, b, c;
cin >> a >> b >> c;
short u = 0;
if (a + b <= c) u += c - a - b + 1;
if (a + c <= b) u += b - a - c + 1;
if (b + c <= a) u += a - b - c + 1;
cout << u;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int arr[3];
for (long long int i = 0; i < 3; i++) {
cin >> arr[i];
}
sort(arr, arr + 3);
if ((arr[2] - arr[1] - arr[0] + 1) <= 0)
cout << "0";
else
cout << (arr[2] - arr[1] - arr[0] + 1);
}
| ### Prompt
Create a solution in cpp for the following problem:
Masha has three sticks of length a, b and c centimeters respectively. In one minute Masha can pick one arbitrary stick and increase its length by one centimeter. She is not allowed to break sticks.
What is the minimum number of minutes she needs to spend increasing the stick's length in order to be able to assemble a triangle of positive area. Sticks should be used as triangle's sides (one stick for one side) and their endpoints should be located at triangle's vertices.
Input
The only line contains tree integers a, b and c (1 β€ a, b, c β€ 100) β the lengths of sticks Masha possesses.
Output
Print a single integer β the minimum number of minutes that Masha needs to spend in order to be able to make the triangle of positive area from her sticks.
Examples
Input
3 4 5
Output
0
Input
2 5 3
Output
1
Input
100 10 10
Output
81
Note
In the first example, Masha can make a triangle from the sticks without increasing the length of any of them.
In the second example, Masha can't make a triangle of positive area from the sticks she has at the beginning, but she can spend one minute to increase the length 2 centimeter stick by one and after that form a triangle with sides 3, 3 and 5 centimeters.
In the third example, Masha can take 33 minutes to increase one of the 10 centimeters sticks by 33 centimeters, and after that take 48 minutes to increase another 10 centimeters stick by 48 centimeters. This way she can form a triangle with lengths 43, 58 and 100 centimeters in 81 minutes. One can show that it is impossible to get a valid triangle faster.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int arr[3];
for (long long int i = 0; i < 3; i++) {
cin >> arr[i];
}
sort(arr, arr + 3);
if ((arr[2] - arr[1] - arr[0] + 1) <= 0)
cout << "0";
else
cout << (arr[2] - arr[1] - arr[0] + 1);
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, maxx;
cin >> a >> b >> c;
maxx = max(c, max(a, b));
if (maxx == b) {
b = c;
c = maxx;
}
if (maxx == a) {
a = c;
c = maxx;
}
cout << max(0, c - (a + b - 1)) << endl;
}
| ### Prompt
Please create a solution in CPP to the following problem:
Masha has three sticks of length a, b and c centimeters respectively. In one minute Masha can pick one arbitrary stick and increase its length by one centimeter. She is not allowed to break sticks.
What is the minimum number of minutes she needs to spend increasing the stick's length in order to be able to assemble a triangle of positive area. Sticks should be used as triangle's sides (one stick for one side) and their endpoints should be located at triangle's vertices.
Input
The only line contains tree integers a, b and c (1 β€ a, b, c β€ 100) β the lengths of sticks Masha possesses.
Output
Print a single integer β the minimum number of minutes that Masha needs to spend in order to be able to make the triangle of positive area from her sticks.
Examples
Input
3 4 5
Output
0
Input
2 5 3
Output
1
Input
100 10 10
Output
81
Note
In the first example, Masha can make a triangle from the sticks without increasing the length of any of them.
In the second example, Masha can't make a triangle of positive area from the sticks she has at the beginning, but she can spend one minute to increase the length 2 centimeter stick by one and after that form a triangle with sides 3, 3 and 5 centimeters.
In the third example, Masha can take 33 minutes to increase one of the 10 centimeters sticks by 33 centimeters, and after that take 48 minutes to increase another 10 centimeters stick by 48 centimeters. This way she can form a triangle with lengths 43, 58 and 100 centimeters in 81 minutes. One can show that it is impossible to get a valid triangle faster.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, maxx;
cin >> a >> b >> c;
maxx = max(c, max(a, b));
if (maxx == b) {
b = c;
c = maxx;
}
if (maxx == a) {
a = c;
c = maxx;
}
cout << max(0, c - (a + b - 1)) << endl;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int a[4], x, y, z;
int main() {
cin >> a[1] >> a[2] >> a[3];
sort(a + 1, a + 4);
x = a[1], y = a[2], z = a[3];
if (x + y > z)
cout << 0;
else
cout << z - x - y + 1;
return 0;
}
| ### Prompt
Create a solution in CPP for the following problem:
Masha has three sticks of length a, b and c centimeters respectively. In one minute Masha can pick one arbitrary stick and increase its length by one centimeter. She is not allowed to break sticks.
What is the minimum number of minutes she needs to spend increasing the stick's length in order to be able to assemble a triangle of positive area. Sticks should be used as triangle's sides (one stick for one side) and their endpoints should be located at triangle's vertices.
Input
The only line contains tree integers a, b and c (1 β€ a, b, c β€ 100) β the lengths of sticks Masha possesses.
Output
Print a single integer β the minimum number of minutes that Masha needs to spend in order to be able to make the triangle of positive area from her sticks.
Examples
Input
3 4 5
Output
0
Input
2 5 3
Output
1
Input
100 10 10
Output
81
Note
In the first example, Masha can make a triangle from the sticks without increasing the length of any of them.
In the second example, Masha can't make a triangle of positive area from the sticks she has at the beginning, but she can spend one minute to increase the length 2 centimeter stick by one and after that form a triangle with sides 3, 3 and 5 centimeters.
In the third example, Masha can take 33 minutes to increase one of the 10 centimeters sticks by 33 centimeters, and after that take 48 minutes to increase another 10 centimeters stick by 48 centimeters. This way she can form a triangle with lengths 43, 58 and 100 centimeters in 81 minutes. One can show that it is impossible to get a valid triangle faster.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int a[4], x, y, z;
int main() {
cin >> a[1] >> a[2] >> a[3];
sort(a + 1, a + 4);
x = a[1], y = a[2], z = a[3];
if (x + y > z)
cout << 0;
else
cout << z - x - y + 1;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
int res = 0;
if (a + b <= c) res += c - (a + b) + 1;
if (a + c <= b) res += b - (a + c) + 1;
if (b + c <= a) res += a - (b + c) + 1;
cout << res;
return 0;
}
| ### Prompt
Your task is to create a cpp solution to the following problem:
Masha has three sticks of length a, b and c centimeters respectively. In one minute Masha can pick one arbitrary stick and increase its length by one centimeter. She is not allowed to break sticks.
What is the minimum number of minutes she needs to spend increasing the stick's length in order to be able to assemble a triangle of positive area. Sticks should be used as triangle's sides (one stick for one side) and their endpoints should be located at triangle's vertices.
Input
The only line contains tree integers a, b and c (1 β€ a, b, c β€ 100) β the lengths of sticks Masha possesses.
Output
Print a single integer β the minimum number of minutes that Masha needs to spend in order to be able to make the triangle of positive area from her sticks.
Examples
Input
3 4 5
Output
0
Input
2 5 3
Output
1
Input
100 10 10
Output
81
Note
In the first example, Masha can make a triangle from the sticks without increasing the length of any of them.
In the second example, Masha can't make a triangle of positive area from the sticks she has at the beginning, but she can spend one minute to increase the length 2 centimeter stick by one and after that form a triangle with sides 3, 3 and 5 centimeters.
In the third example, Masha can take 33 minutes to increase one of the 10 centimeters sticks by 33 centimeters, and after that take 48 minutes to increase another 10 centimeters stick by 48 centimeters. This way she can form a triangle with lengths 43, 58 and 100 centimeters in 81 minutes. One can show that it is impossible to get a valid triangle faster.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
int res = 0;
if (a + b <= c) res += c - (a + b) + 1;
if (a + c <= b) res += b - (a + c) + 1;
if (b + c <= a) res += a - (b + c) + 1;
cout << res;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int a[4];
int main() {
scanf("%d %d %d", a, a + 1, a + 2);
sort(a, a + 3);
if (a[0] + a[1] > a[2]) {
puts("0");
} else
printf("%d\n", a[2] - (a[0] + a[1]) + 1);
}
| ### Prompt
Please formulate a cpp solution to the following problem:
Masha has three sticks of length a, b and c centimeters respectively. In one minute Masha can pick one arbitrary stick and increase its length by one centimeter. She is not allowed to break sticks.
What is the minimum number of minutes she needs to spend increasing the stick's length in order to be able to assemble a triangle of positive area. Sticks should be used as triangle's sides (one stick for one side) and their endpoints should be located at triangle's vertices.
Input
The only line contains tree integers a, b and c (1 β€ a, b, c β€ 100) β the lengths of sticks Masha possesses.
Output
Print a single integer β the minimum number of minutes that Masha needs to spend in order to be able to make the triangle of positive area from her sticks.
Examples
Input
3 4 5
Output
0
Input
2 5 3
Output
1
Input
100 10 10
Output
81
Note
In the first example, Masha can make a triangle from the sticks without increasing the length of any of them.
In the second example, Masha can't make a triangle of positive area from the sticks she has at the beginning, but she can spend one minute to increase the length 2 centimeter stick by one and after that form a triangle with sides 3, 3 and 5 centimeters.
In the third example, Masha can take 33 minutes to increase one of the 10 centimeters sticks by 33 centimeters, and after that take 48 minutes to increase another 10 centimeters stick by 48 centimeters. This way she can form a triangle with lengths 43, 58 and 100 centimeters in 81 minutes. One can show that it is impossible to get a valid triangle faster.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int a[4];
int main() {
scanf("%d %d %d", a, a + 1, a + 2);
sort(a, a + 3);
if (a[0] + a[1] > a[2]) {
puts("0");
} else
printf("%d\n", a[2] - (a[0] + a[1]) + 1);
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int a, b, c;
cin >> a >> b >> c;
int a1 = min(a, min(c, b));
int c1 = max(a, max(c, b));
int b1 = a + b + c - a1 - c1;
cout << max(0, c1 - b1 - a1 + 1);
}
| ### Prompt
Please formulate a Cpp solution to the following problem:
Masha has three sticks of length a, b and c centimeters respectively. In one minute Masha can pick one arbitrary stick and increase its length by one centimeter. She is not allowed to break sticks.
What is the minimum number of minutes she needs to spend increasing the stick's length in order to be able to assemble a triangle of positive area. Sticks should be used as triangle's sides (one stick for one side) and their endpoints should be located at triangle's vertices.
Input
The only line contains tree integers a, b and c (1 β€ a, b, c β€ 100) β the lengths of sticks Masha possesses.
Output
Print a single integer β the minimum number of minutes that Masha needs to spend in order to be able to make the triangle of positive area from her sticks.
Examples
Input
3 4 5
Output
0
Input
2 5 3
Output
1
Input
100 10 10
Output
81
Note
In the first example, Masha can make a triangle from the sticks without increasing the length of any of them.
In the second example, Masha can't make a triangle of positive area from the sticks she has at the beginning, but she can spend one minute to increase the length 2 centimeter stick by one and after that form a triangle with sides 3, 3 and 5 centimeters.
In the third example, Masha can take 33 minutes to increase one of the 10 centimeters sticks by 33 centimeters, and after that take 48 minutes to increase another 10 centimeters stick by 48 centimeters. This way she can form a triangle with lengths 43, 58 and 100 centimeters in 81 minutes. One can show that it is impossible to get a valid triangle faster.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int a, b, c;
cin >> a >> b >> c;
int a1 = min(a, min(c, b));
int c1 = max(a, max(c, b));
int b1 = a + b + c - a1 - c1;
cout << max(0, c1 - b1 - a1 + 1);
}
``` |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.