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. thinkphp自定义权限管理之名称判断

    权限管理,就是给不同的用户分配不同的权限.当用户登录或者操作时候进行判断,来阻止用户进行权限以外的操作.本次讲的是当用户登录一刻,只显示权限开启的内容. 一.建立数据库. 1.权限表funcla.来存 ...

  2. JSP页面以及简单的指令

    —JSP(Java Server Pages)是指: —在HTML中嵌入Java脚本语言 —由应用服务器中的JSP引擎来编译和执行嵌入的Java脚本语言命令 —然后将生成的整个页面信息返回给客户端 页 ...

  3. phpexcel的写操作将数据库中的数据导入到excel中

    这个版本据说是可以支持excel2007,但是我使用2007编辑的xlsx是无法获得该库的支持.于是乎我就将它转化为2003.感觉支持地很好. 下面介绍一下具体的使用: require_once('. ...

  4. 关于Java擦除特性

    package thinkingInJava; /* * 模拟擦除 */ public class SimpleHolder { private Object obj ; public void se ...

  5. PowerDesigner 15.2入门学习 二

    PowerDesigner中如何生成主键和自增列 1.SQL Server版本: 第一步,首先要建立与数据库的连接,方法较多,这里举个例子: http://www.cnblogs.com/netsql ...

  6. Careercup | Chapter 8

    8.2 Imagine you have a call center with three levels of employees: respondent, manager, and director ...

  7. 【iCore3双核心板】【4.3寸液晶驱动板爆照!】

     [源代码完全开源,过几天连同硬件一起发布] 花了好久的时间,我们的fpga工程师才完成这液晶模块的驱动代码,其核心价值如下: 1.完全基于fpga驱动,sdram当做缓存: 2.内建双缓冲机制:方便 ...

  8. java环境搭建系列:JDK从下载安装到简单使用

    最近,问的比较多的问题居然是jdk的问题,对于新手来说这确实有点难度,毕竟一个人经常上网浏览新闻和观看视频的人,一下子开始一门编程语言的环境搭建.这中间需要一个慢慢适应的过程.回想当初我在这个阶段也很 ...

  9. 新安装个Myeclipse,导入以前做的程序后程序里好多错,提示The import java.util cannot be resolved

    原因:这是由于你的项目buildpath不对原来的项目,比如采用了原先的MyEclipse自带的jdk (D:\myeclipse\XXXXXX)结果,你现在换了一个,原来的没了就导致了现在这种错误, ...

  10. QTP功能点笔记

    1.QTP启动应用程序的几种方法 1)用SystemUtil.Run 1 SystemUtil.Run "C:\Program Files (x86)\HP\QuickTest Profes ...