Coin

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1020    Accepted Submission(s):
507

Problem Description
Moon has many coins, but only contains two value types
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.

 
Input
The first line contains an integer T, indicates the
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)
 
Output
For each test case, output one line contains the number
n adapt the problem description.
 
Sample Input
1
5 7
 
Sample Output
23
 
Source
 
题意:给你两种素数,每种素数个数不限,求哪个数字后所有的数字都可以通过这两种素数组合构成
 
做最短路的时候无意中看到的题,很简单的数学推理,代码短顺手敲了~
 
设所求为n,那么n+a、n+b可以用a、b线性表出,而n不可。
所以 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的更多相关文章

  1. 题解报告:hdu 2069 Coin Change(暴力orDP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2069 Problem Description Suppose there are 5 types of ...

  2. HDU 2069 Coin Change

    Coin Change Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...

  3. HDU 3951 Coin Game (简单博弈)

    Coin Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  4. hdu 2069 Coin Change(完全背包)

    Coin Change Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  5. HDU 2069 Coin Change(完全背包变种)

    题意:给你5种银币,50 25 10 5 1,问你可以拼成x的所有可能情况个数,注意总个数不超过100个 组合数问题,一看就是完全背包问题,关键就是总数不超过100个.所有我们开二维dp[k][j], ...

  6. hdu 3951 - Coin Game(找规律)

    这道题是有规律的博弈题目,,, 所以我们只需要找出规律来就ok了 牛人用sg函数暴力找规律,菜鸟手工模拟以求规律...[牢骚] if(m>=2) { if(n<=m) {first第一口就 ...

  7. hdu 3951 Coin Game 博弈论

    思路: 当n<=k时,先手必胜: 当k=1时,n为奇数先手胜,否则后手胜: 当k>1时,先手操作之后必定形成链,后手操作后形成二条一样的链,之后,先手怎么操作,后手就怎么操作,则后手必胜. ...

  8. HDU 2844 Coin 多重背包

    Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  9. 【hdu 3951】Coin Game

    Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s) ...

随机推荐

  1. java的boolean和Boolean

    boolean是基本数据类型Boolean是它的封装类,和其他类一样,有属性有方法,可以new,例如: Boolean bl= new Boolean("true"); // bo ...

  2. 计蒜客 Flashing Fluorescents(状压DP)

    You have nn lights, each with its own button, in a line. Pressing a light’s button will toggle that ...

  3. 集训队日常训练20180513-DIV1

    A.3132 给一个有向图,问能否从任意点出发都能进入一个环中. 深搜. #include<bits/stdc++.h> using namespace std; ; vector< ...

  4. jquery 调用asp.net后台代码

    1.需要引用对应的命名空间 System.Web.Services 2.后台方法: 必须是static 约束   必须添加[WebMethod()] 属性 示例: <script type=&q ...

  5. Vue--vue中的组件、组件绑定事件和数据、私有组件、子组件,父子组件参数互传

    一.公有组件以及组件的使用和特点 <!DOCTYPE html> <html lang="en"> <head> <meta charse ...

  6. 微信小程序--每个独立的page的page.json只能修改window属性

    app.json 配置项列表 app.json文件用来对微信小程序进行全局配置,决定页面文件的路径.窗口表现.设置网络超时时间.设置多 tab 等. window配置 用于设置小程序的状态栏.导航条. ...

  7. jquery源码学习(三)—— jquery.prototype主要属性和方法

    上次我们学习了jquery中的主要对象jQuery和一些变量,现在我们开始学习jquery的原型 98行声明了jQuery.fn = jQuery.prototype = {} 285行jQuery. ...

  8. SQLServer2005 没有日志文件(*.ldf) 只有数据文件(*.mdf) 恢复数据库的方法

    代码如下: exec sp_attach_db exun,'d:\exun2.mdf' (可能执行一次不能成功,测试了下,有时候需要执行2次以上命令才行) 执行了之后,记得刷新数据库,不然是不会显示的

  9. Linux下的权限管理

    Linux系统上对文件的权限有着严格的控制,用于如果相对某个文件执行某种操作,必须具有对应的权限方可执行成功. Linux下文件的权限类型一般包括读,写,执行.对应字母为 r.w.x. Linux下权 ...

  10. Codeforces Round #304 (Div. 2) B. Soldier and Badges【思维/给你一个序列,每次操作你可以对一个元素加1,问最少经过多少次操作,才能使所有元素互不相同】

    B. Soldier and Badges time limit per test 3 seconds memory limit per test 256 megabytes input standa ...