Ultraviolet A-1435 business cards (number theory)

Source: Internet
Author: User

Description

Running a paper shop is not an easy job, especially with harsh MERs. today they brought their own rectangular sheets of paper, asking you to cut it into rectangular business cards of specific size. moreover, they require that all the paper (which may not be cheap, but is definitely not that expensive !) Has to be used, I. e. no tiny bit may be left over. moreover, the brilliant idea of cutting the sheet into very small pieces, and then gluing them together in desired sheets was laughed.

An example of a 9 × 6 paper sheet divided into 2 × 3 cards is given below.

Input

The input contains several test cases. The first line contains the number of test casesT(T105). ThenTTest Cases Follow. Each of them consists of one line containing four IntegersA,B,C,D(1A,B,C,D109). NumbersAAndBAre dimensions of each business card;CAndDAre dimensions of the paper sheet.

Output

For each test case output one line containing word'Yes'If it is possible to divide the whole sheet into business cards, and'No'Otherwise.

Sample Input

4 2 3 9 62 3 8 62 3 6 82 3 5 7

Sample output

Yes yes no question: Here are four numbers for A, B, C, and D. Let's ask you how to divide the matrix of C * d into several matrix ideas of a * B: Situation-based discussion: 1. All rows are placed vertically; 2. All rows are placed horizontally; 3. Note that the length or width can only be combined in 3rd cases, it means solving the two situations of AX + by = c | D. You can try to draw a picture.
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>typedef long long ll;using namespace std;int find(ll a, ll b, ll c) {if (a < b)swap(a, b);for (ll i = a; i < c; i += a)if ((c - i) % b == 0)return 1;return 0;}int main() {ll a, b, c, d;int t;scanf("%d", &t);while (t--) {scanf("%lld%lld%lld%lld", &a, &b, &c, &d);if ((c % a == 0 && d % b == 0) || (d % a == 0 && c % b == 0))printf("YES\n");else if (c % a == 0 && c % b == 0 && find(a, b, d))printf("YES\n");else if (d % a == 0 && d % b == 0 && find(a, b, c))printf("YES\n");else printf("NO\n");}return 0;}


Ultraviolet A-1435 business cards (number theory)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.