hdu 2662 Coin
Coin
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1020 Accepted Submission(s):
507
which is 5 cents and 7 cents, Some day he find that he can get any value which
greater than 23 cents using some of his coins. For instance, he can get 24 cents
using two 5 cents coins and two 7 cents coins, he can get 25 cents using five 5
cents coins, he can get 26 cents using one 5 cents coins and three 7 cents coins
and so on.
Now, give you many coins which just contains two value types
just like Moon, and the two value types identified by two different prime number
i and j. Can you caculate the integer n that any value greater than n can be
created by some of the given coins.
number of test cases.
For each test case, there are two different prime i
and j separated by a single space.(2<=i<=1000000, 2<=j<=1000000)
n adapt the problem description.
所以 n+a=x1*a+y1*b,n+b=x2*a+y2*b
所以 n=(x1-1)*a+y1*b n=x2*a+(y2-1)*b
因为n不能被线性表出,所以x1=0,y2=0
所以 n+a=y1*b,n+b=x2*a
所以 n+a=y1*b,n+a=(x2+1)*a-b
所以 (x2+1)*a-b是b的倍数
因为a、b互质,所以(x2+1)是b的倍数
因为求最小的n,所以选最小的x2值,所以取(x2+1)为b
所以 n+a=b*a-b,n=a*b-a-b
证毕
#include <iostream>
#include <cstdio>
#define ll __int64
using namespace std;
int main()
{
int T,i,j;
ll n,m;
scanf("%d",&T);
while(T--)
{
scanf("%I64d%I64d",&n,&m);
ll s=n*m-n-m;
printf("%I64d\n",s);
}
return ;
}
hdu 2662 Coin的更多相关文章
- 题解报告:hdu 2069 Coin Change(暴力orDP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2069 Problem Description Suppose there are 5 types of ...
- HDU 2069 Coin Change
Coin Change Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...
- HDU 3951 Coin Game (简单博弈)
Coin Game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- hdu 2069 Coin Change(完全背包)
Coin Change Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- HDU 2069 Coin Change(完全背包变种)
题意:给你5种银币,50 25 10 5 1,问你可以拼成x的所有可能情况个数,注意总个数不超过100个 组合数问题,一看就是完全背包问题,关键就是总数不超过100个.所有我们开二维dp[k][j], ...
- hdu 3951 - Coin Game(找规律)
这道题是有规律的博弈题目,,, 所以我们只需要找出规律来就ok了 牛人用sg函数暴力找规律,菜鸟手工模拟以求规律...[牢骚] if(m>=2) { if(n<=m) {first第一口就 ...
- hdu 3951 Coin Game 博弈论
思路: 当n<=k时,先手必胜: 当k=1时,n为奇数先手胜,否则后手胜: 当k>1时,先手操作之后必定形成链,后手操作后形成二条一样的链,之后,先手怎么操作,后手就怎么操作,则后手必胜. ...
- HDU 2844 Coin 多重背包
Coins Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- 【hdu 3951】Coin Game
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s) ...
随机推荐
- 如何在TypeScript中使用JS类库
使用流程 1.首先要清除类库是什么类型,不同的类库有不同的使用方式 2.寻找声明文件 JS类库一般有三类:全局类库.模块类库.UMD库.例如,jQuery是一种UMD库,既可以通过全局方式来引用,也可 ...
- TYVJ4239 [NOIP2015提高组DayT3]斗地主
P2668 斗地主 题目描述 牛牛最近迷上了一种叫斗地主的扑克游戏.斗地主是一种使用黑桃.红心.梅花.方片的A到K加上大小王的共54张牌来进行的扑克牌游戏.在斗地主中, 牌的大小关系根据牌的数码表示如 ...
- json原生解析
身为新手,在运用网络解析json数据的时候,发现先会用Gson等框架解析json,然后就懒起来学原生解析了,这下在看别人写的demo的时候就尴尬了,一块块的,不懂写什么,气氛十分尴尬. 不多说,先来条 ...
- vue使用填坑之生命周期钩子的 this 上下文
每个Vue实例在被创建的时候都需要经过一系列的初始过程,如设置数据监听,编译模版,将实例挂载到DOM并在数据变化的时候更新DOM.在这个过程中,也会运行一些叫生命周期钩子的函数.如created, m ...
- python 基本数据结构 ndarray
- PHPCMS快速建站系列之getcache()的用法
/** * 读取缓存,默认为文件缓存,不加载缓存配置. * @param string $name 缓存名称 * @param $filepath 数据路径(模块名称) caches/cache_$f ...
- POJ 2078
16ms 解法: #include <cstdio> //using namespace std; ][]; ][]; ]; ]; int n,min,max; void solve(in ...
- database homework1
mysql> select * from teacher_info; +----+------+-----+--------+---------+ | id | name | age | sal ...
- Directx11教程(20) 一个简单的水面
原文:Directx11教程(20) 一个简单的水面 nnd,以前发的这篇教程怎么没有了?是我自己误删除了,还是被系统删除了? 找不到存稿了,没有心情再写一遍了. 简单说一下,本篇教程就是实 ...
- bzoj1412 狼和羊的故事
Description “狼爱上羊啊爱的疯狂,谁让他们真爱了一场:狼爱上羊啊并不荒唐,他们说有爱就有方向......” Orez听到这首歌,心想:狼和羊如此和谐,为什么不尝试羊狼合养呢?说干就干! O ...