Jug Hard

Time Limit: 10 Sec Memory Limit: 128 MB

Submit: 1172 Solved: 180

Description

You have two empty jugs and tap that may be used to fill a jug. When filling a jug from the tap, you can only fill it completely (i.e., you cannot partially fill it to a desired level, since there are no volume measurements on the jug).

You may empty either jug at any point.

You may transfer water between the jugs: if transferring water from a larger jug to a smaller jug, the smaller jug will be full and there will be water left behind in the larger jug.

Given the volumes of the two jugs, is it possible to have one jug with some specific volume of water?

Input

The first line contains T, the number of test cases (1 ≤ T 100 000). Each test case is composed of three integers: a b d where a and b (1 ≤ a, b ≤ 10 000 000) are the volumes of the two jugs, and d is the desired volume of water to be generated. You can assume that d ≤ max(a,b).

Output

For each of the T test cases, output either Yes or No, depending on whether the specific volume of water can be placed in one of the two jugs.

Sample Input

3

8 1 5

4 4 3

5 3 4

Sample Output

Yes

No

Yes

an+bn=d;

证明等式的成立,就是扩展欧几里得的证明

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std; int GCD(int a,int b)
{
return b==0?a:GCD(b,a%b);
} int main()
{
int T;
int n ,m,d; scanf("%d",&T);
while(T--)
{
scanf("%d %d %d",&n,&m,&d);
printf("%s\n",d%GCD(n,m)==0?"Yes":"No"); }
return 0;
}

浙江理工2015.12校赛-G Jug Hard的更多相关文章

  1. 浙江理工2015.12校赛-A

    孙壕请一盘青岛大虾呗 Time Limit: 5 Sec Memory Limit: 128 MB Submit: 577 Solved: 244 Description 话说那一年zstu与gdut ...

  2. 浙江理工2015.12校赛-F Landlocked

    Landlocked Time Limit: 5 Sec Memory Limit: 128 MB Submit: 288 Solved: 39 Description Canada is not a ...

  3. 浙江理工2015.12校赛-B 七龙珠

    七龙珠 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 781 Solved: 329 Description 话说孙壕请吃了青岛大虾后,一下子变穷了,就 ...

  4. 2015 GDUT校赛

    周末打了个GDUT的校赛,也是作为SCAU的一场个人排位. 比赛中竟然卡了个特判,1个半钟就切了5条了,然后一直卡. 还有其他两条可以做的题也没法做了,性格太执着对ACM来说也是错呀. 讲回正题 . ...

  5. 2017年浙江理工大学程序设计竞赛校赛 题解&源码(A.水, D. 简单贪心 ,E.数论,I 暴力)

    Problem A: 回文 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 1719  Solved: 528 Description 小王想知道一个字 ...

  6. 2015 多校赛 第七场 1011 (hdu 5379)

    题意:给定一棵树,树上有 n 个节点.问有多少种方案,使得在每个节点上依次放置数 1~n 后,每个节点的儿子节点上的数连续(比如 1 为根,有1-2,1-3,1-4,则令2,3,4上的数连续),每个子 ...

  7. 2015 多校赛 第五场 1010 (hdu 5352)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5352 看题看得心好累. 题目大意: 给出 n 个点,依次执行 m 次操作:输入“1 x”时,表示将与 ...

  8. 2015 多校赛 第一场 1007 (hdu 5294)

    总算今天静下心来学算法.. Description Innocent Wu follows Dumb Zhang into a ancient tomb. Innocent Wu’s at the e ...

  9. 2018年浙江理工大学程序设计竞赛校赛 Problem I: 沙僧

    沙僧 思路: dfs序+差分数组 分层考虑,通过dfs序来查找修改的区间段,然后用差分数组修改 代码: #include<bits/stdc++.h> using namespace st ...

随机推荐

  1. C# 截取字符串

    1.根据单个分隔字符用split截取 例如 string st="GT123_1"; string[] sArray=st.split("_"); 即可得到sA ...

  2. chineseChess

    最近学习了chineseChess的Qt实现,把一些东西总结一下: 实现功能: 1.人人对战 2.人机对战 3.网络版 一.基础性工作:(人人对战) 1.棋盘和棋子的绘制(QPinter,drawLi ...

  3. php中使用while遍历二维数组的方法

    <?php $contact=array( 'gao'=>array('ID'=>1,'name'=>'高某','company'=>'A公司','addr'=>' ...

  4. 把验证码和生成时间负值给$_SESSION[vCode]生成图像给浏览器

    php 图片 中文验证码 <img src="verify_image.php" alt="点此刷新验证码" name="verify_code ...

  5. javascript 原型链

    浅谈JS原型链 原型链 ECMAScript中描述了原型链的概念.我们知道ECMAScript并不像C++,Java那样使用类,但是对象仍然可以通过多种方式创建,其中就有构造函数方式.每个构造函数都有 ...

  6. JS中的特有语句-for in

    <script> /* *js中特有语句for in *for(变量 in 对象)//对对象进行变量的语句 *{ *} */ var arr = [32,80,65]; for(i in ...

  7. swift 2.x学习笔记(一)

    p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #008400 } p.p2 { margin: 0.0px 0. ...

  8. Redis和Memcache对比及选择(转载)

  9. IEnumerable、GetEnumerator、IEnumerator的理解

    概念文字性的东西,我们就不说了,这里我们来点具体的实例第呀: 实例一: using System; using System.Collections; using System.Collections ...

  10. linux的mount(挂载)命令

    前言: 1.挂载点必须是一个目录. 2.一个分区挂载在一个已存在的目录上,这个目录可以不为空,但挂载后这个目录下以前的内容将不可用. 对于其他操作系统建立的文件系统的挂载也是这样.但是需要理解的是:光 ...