Luo Gu P3951 Oscar doubts

Title Description

There are two kinds of face value of coins in the hands of Oscar's two par value are positive integers and prime to each other. Each has numerous Oscar gold. Without the change, the two gold alone, some items he is unable to accurately paid. Now Oscar would like to know the exact items can not pay, the most expensive value is how much gold? Note: input data to ensure the presence of goods not paid for Oscar accurate.

Input Format

Two positive integers  a and  B, separated by a space therebetween, showing the coins in the denomination Oscar.

Output Format

A positive integer  case N, said they did not give change, the value of the most expensive items in the hands of Oscar gold can not be accurately paid.


Since the two prime numbers, so gcd (a, b) = 1 lcm (a, b) = a * b
If a number k can be expressed, then k = ax + by
N = ax + by legally can not be expressed as N, there are N = ax (mod b)
If N is not valid, then y <0
Because the maximum N, x maximum (mod b)
Therefore, x = b-1 y = -1
The N = a * (b-1) -b
Expand obtain N = ab-ab
// Note range, to open long long
Exam practice: playing table to find the law
#include<iostream>
using namespace std;
int main()
{
    long long a,b;
    cin>>a>>b;
    cout<<a*b-a-b;
    return 0;
}

 

 
 
 
 

Guess you like

Origin www.cnblogs.com/nenT/p/11373696.html