Oscar doubts [2017TG D1T1]

It should be called programmer 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  N in the case, said they did not give change, the value of the most expensive items in the hands of Oscar gold can not be accurately paid.

Sample input and output

Entry 
3 7
Export
11

Description / Tips

Sample Description 1 [O]

Oscar hands of a face value of 3 and 7 gold numerous and can not pay the exact amount without the change in the value of 1, 2,4,5,8,11 items, the most expensive item value is 11 , compared with 11 you can buy items, such as:

12=3×4+7×0

13=3×2+7×1

14=3×0+7×2

15=3×5+7×0

 

Code

#include<cstdio>
using namespace std;

int main()
{
    long long a,b;
    scanf("%lld%lld",&a,&b);
    printf("%lld",a*b-a-b);
    return 0;
 } 

Hmmm, so sloppy code. . Actually are so scratchy code? ? ? ! ! !

Good bar, looked luogu solution to a problem in the bigwigs of proof to prove the perfect [my] property konjac

analysis

May assume  a <b

Suppose the answer is  x

If X m A (MOD B) ( . 1 m B - . 1 )

which is

x=ma+nb(1mb1)

Obviously when  n- 0 when  x  may be  a, b  represented, are not intended to questions.

Therefore, when  n = -1 when x obtain the maximum value, then x = m A - B.

Obviously when  m m obtain the maximum value  B - . 1 when x maximum, then x = ( B - . 1 ) A - B = A B - A - B

Thus  a, b are not represented by the maximum number is  ab - ab

 

Guess you like

Origin www.cnblogs.com/zhugezisong/p/11319347.html