tim so phan so
#include <iostream>
using namespace std;
int gcd(int x, int y){
int s;
while (y != 0){
s = x % y;
x = y;
y = s;
}
return x+y;
}
bool noBigger(int a, int b, int c, int d){
return a*c <= b*d;
}
int counting(int a, int b, int c, int d, int n){
int x, y, counter = 0;
for (x=1; x<=n; x++){
for (y=1; y<=n; y++){
if (gcd(x, y) == 1 && noBigger(a, b, x, y) && noBigger(x, y, c, d)){
counter++;
}
}
}
return counter;
}
int main(){
int i, k, a, b, c, d, n;
cout<<"k = ";
cin>> k;
for (i=1; i<=k; i++){
cin>> a>> b>> c>> d>> n;
cout<< counting(a, b, c, d, n)<<endl;
}
system("pause");
return 0;
}
Bạn đang đọc truyện trên: AzTruyen.Top