JZOJ 5473. 【NOIP2017提高组正式赛】小凯的疑惑
2017-11-21 15:56
260 查看
Description
小凯手中有两种面值的金币,两种面值均为正整数且彼此互素。每种金币小凯都有无数个。在不找零的情况下,仅凭这两种金币,有些物品他是无法准确支付的。现在小凯想知道在无法准确支付的物品中,最贵的价值是多少金币?注意:输入数据保证存在小凯无法准确支付的商品。
Input
输入数据仅一行,包含两个正整数 a 和 b,它们之间用一个空格隔开,表示小凯手中金币的面值。
Output
输出文件仅一行,一个正整数 N,表示不找零的情况下,小凯用手中的金币不能准确支付的最贵的物品的价值。
Sample Input
【输入样例 1】
3 7Sample Output
【输出样例 1】
11【输入输出样例 1 说明】
小凯手中有面值为3和7的金币无数个,在不找零的前提下无法准确支付价值为1、2、4、5、8、11 的物品,其中最贵的物品价值为 11,比 11 贵的物品都能买到,比如:12 = 3 * 4 + 7 * 0
13 = 3 * 2 + 7 * 1
14 = 3 * 0 + 7 * 2
15 = 3 * 5 + 7 * 0
……
Data Constraint
对于 30%的数据: 1 ≤ a,b ≤ 50。对于 60%的数据: 1 ≤ a,b ≤ 10,000。
对于 100%的数据:1 ≤ a,b ≤ 1,000,000,000。
Solution
显然,答案为 (a−1)∗(b−1)−1即 a∗b−a−b
Code
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; int read() { int X=0,w=1; char ch=0; while(ch<'0' || ch>'9') {if(ch=='-') w=-1;ch=getchar();} while(ch>='0' && ch<='9') X=(X<<3)+(X<<1)+ch-'0',ch=getchar(); return X*w; } int main() { int n=read(),m=read(); long long ans=(long long)n*m; printf("%lld",ans-n-m); return 0; }
相关文章推荐
- 5473. 【NOIP2017提高组正式赛】小凯的疑惑
- JZOJ 5477. 【NOIP2017提高组正式赛】宝藏
- JZOJsenior5473.【NOIP2017提高组】day1T1小凯的疑惑
- JZOJ 5475. 【NOIP2017提高组正式赛】逛公园
- JZOJ 5478. 【NOIP2017提高组正式赛】列队
- JZOJ 5476. 【NOIP2017提高组正式赛】奶酪
- JZOJ 5474. 【NOIP2017提高组正式赛】时间复杂度
- NOIP2017 Day1 T1 小凯的疑惑 真·奥义·蒟蒻总结
- JZOJ5379. 【NOIP2017提高A组模拟9.21】Victor爱数字 数位DP
- JZOJ 5386. 【NOIP2017提高A组模拟9.23】碎
- 5478. 【NOIP2017提高组正式赛】列队
- [置顶] 【NOIp 2017】小凯的疑惑(置顶)
- 【JZOJ 5393】【NOIP2017提高A组模拟10.5】Snake vs Block
- [JZOJ5394]【NOIP2017提高A组模拟10.5】Ping
- JZOJ5397. 【NOIP2017提高A组模拟10.6】Biology
- 【JZOJ 5395】【NOIP2017提高A组模拟10.6】Count
- JZOJ5400. 【NOIP2017提高A组模拟10.7】Repulsed
- JZOJ 5401. 【NOIP2017提高A组模拟10.8】Star Way To Heaven
- jzoj5330 【NOIP2017提高A组模拟8.22】密码
- 【JZOJ5328】【NOIP2017提高A组模拟8.22】世界线