小凯的疑惑 数学
题目描述
小凯手中有两种面值的金币,两种面值均为正整数且彼此互素。每种金币小凯都有 无数个。在不找零的情况下,仅凭这两种金币,有些物品他是无法准确支付的。现在小 凯想知道在无法准确支付的物品中,最贵的价值是多少金币?注意:输入数据保证存在 小凯无法准确支付的商品。
输入输出格式
输入格式:两个正整数 aaa 和 bbb,它们之间用一个空格隔开,表示小凯中金币的面值。
输出格式:一个正整数 NNN,表示不找零的情况下,小凯用手中的金币不能准确支付的最贵的物品的价值。
输入输出样例
说明
【输入输出样例 1 说明】
小凯手中有面值为333和777的金币无数个,在不找零的前提下无法准确支付价值为1,2,4,5,8,111, 2,4,5,8,111,2,4,5,8,11 的物品,其中最贵的物品价值为 111111,比11 1111 贵的物品都能买到,比如:
12=3×4+7×012 = 3 \times 4 + 7 \times 012=3×4+7×0
13=3×2+7×113 = 3 \times 2 + 7 \times 113=3×2+7×1
14=3×0+7×214 = 3 \times 0 + 7 \times 214=3×0+7×2
15=3×5+7×015 = 3 \times 5 + 7 \times 0 15=3×5+7×0
【数据范围与约定】
对于 30%30\%30%的数据: 1≤a,b≤501 \le a,b \le 50 1≤a,b≤50。
对于 60%60\%60%的数据: 1≤a,b≤1041 \le a,b \le 10^4 1≤a,b≤104。
对于100% 100\%100%的数据:1≤a,b≤1091 \le a,b \le 10^9 1≤a,b≤109。
假设答案为x;
那么如果 x= m*a mod b;
那么 x=m*a + n*b;
显然 n>=0时满足条件;
所以最大不满足时 n=-1;
那么 m 最大取 b-1 ;
所以 x=(b-1)*a-b=a*b - a - b;
完毕;
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
//#include<cctype>
//#pragma GCC optimize(2)
using namespace std;
#define maxn 200005
#define inf 0x7fffffff
//#define INF 1e18
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
#define rdult(x) scanf("%lu",&x)
#define rdlf(x) scanf("%lf",&x)
#define rdstr(x) scanf("%s",x)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const long long int mod = 1e9 + 7;
#define Mod 1000000000
#define sq(x) (x)*(x)
#define eps 1e-3
typedef pair<int, int> pii;
#define pi acos(-1.0)
//const int N = 1005;
#define REP(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> pii;
inline ll rd() {
ll x = 0;
char c = getchar();
bool f = false;
while (!isdigit(c)) {
if (c == '-') f = true;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return f ? -x : x;
}
ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a%b);
}
ll sqr(ll x) { return x * x; }
/*ll ans;
ll exgcd(ll a, ll b, ll &x, ll &y) {
if (!b) {
x = 1; y = 0; return a;
}
ans = exgcd(b, a%b, x, y);
ll t = x; x = y; y = t - a / b * y;
return ans;
}
*/
int main() {
//ios::sync_with_stdio(0);
ll a, b; cin >> a >> b;
cout << a * b - a - b << endl;
return 0;
}