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) ...
随机推荐
- mysql 无法存储joda time的datetime类型
com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect datetime value: '\xAC\xED\x00\x05sr\x ...
- 洛谷 P1036 选数【背包型DFS/选or不选】
题目描述 已知 n 个整数 x1,x2,…,xn,以及一个整数 k(k<n).从 n 个整数中任选 k 个整数相加,可分别得到一系列的和.例如当 n=4,k=3,4 个整数分别为 3,7,12, ...
- 出现$(#form).validate is not a function的问题
最近为项目写cms系统,在新增/编辑文章的页面,一些input诸如文章题目,作者等等需要验证是否已经填写,于是使用jquery.validate.js来做这个工作,自己写了个验证的validate.j ...
- Vbulletin Used to Show Malicious Advertisements
In the past, we have seen a massive amount of vBulletin websites compromised through theVBSeo Vulner ...
- 2019阿里云开年Hi购季域名与商标分会场全攻略!
2019阿里云云上Hi购季活动已经于2月25日正式开启,从已开放的活动页面来看,活动分为三个阶段: 2月25日-3月04日的活动报名阶段.3月04日-3月16日的新购满返+5折抢购阶段.3月16日-3 ...
- QT_强杀进程
#ifdef WIN32 bool res = false; HANDLE hToolHelp32Snapshot; hToolHelp32Snapshot = CreateToolhelp32Sna ...
- Location 位置 history
拆分出来地址 让地址各归其位 search案例 查找历史记录跳转
- 排序函数中比较函数cmp的理解
无论是使用 sort() 或者 qsort(), 都会使用到自己定义比较函数, 习惯上定义为 cmp 如: int cmp(const void *x, const void *y) { return ...
- word Stock Market Indices
Stock Market Indices USA Africa Asia and Pacific Canada Europe Middle East South America Internation ...
- JS文字球状放大效果
在线演示 本地下载