Luo Gu P3951 Oscar doubts (赛瓦维斯特 Theorem)

Topic: P3951 Oscar doubts: https://www.luogu.org/problemnew/show/P3951


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 and output formats

Input formats:

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

Output formats:

A positive integer NN 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.

Sample input and output

Input Sample # 1:
3 7
Output Sample # 1:
11

Explanation

Sample Description 1 [O]

Oscar hands of a face value of 33 3 and 77 gold coins countless 7 can not pay the exact amount without the change in the value of 1,2,4,5,8,111, 2,4,5,8,11 1 , 2 , 4 , 5 , 8 , 1 item 1, wherein the value of the most expensive items for 1111 1 1, more than 11 11 1 you can buy 1 item, such as:

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

[Agreed] with the data range

For 30% 30 \% . 3 0 % of the data: 1 ≦ a, b≤501 \ Le A, B \ Le 50 . 1 A , B . 5 0.

For 60% 60 \% . 6 0 % Data: 1 ≦ a, b≤1041 \ Le A, B \ Le ^ 10. 4 . 1 A , B . 1 0 . 4.

For 100% 100 \% . 1 0 0 % Data: 1 ≦ a, b≤1091 \ Le A, B \ Le ^. 9 10 . 1 A , B . 1 0 . 9.


Related blog: https://www.cnblogs.com/xxzh/p/9178564.html 

     https://www.cnblogs.com/jefflyy/p/7819858.html

This question is a question related to number theory.

For this type of problem, we have summarized the general rules:

  ! ! Encountered mathematical problems hit the table to find the law! !

For this problem we find C = ab-ab.

 

Here, we know:

  赛瓦维斯特 Theorem: Given a, b is a positive integer greater than 1, gcd (a, b) = 1, so that the indefinite equation ax + by = C maximum integer no negative solution C = ab-ab.

 

So, we can easily draw:

 1 //
 2 #include <iostream>
 3 #include <cstdio>
 4 #include <cctype>
 5 #include <cstring>
 6 #include <cmath>
 7 #include <algorithm>
 8 using namespace std;
 9 typedef unsigned long long ll;
10 #define ri register ll
11  
12 ll a,b;
13  
14 signed main()
15 {
16     ios::sync_with_stdio(0),cin.tie(0);
17     cin>>a>>b;
18     cout<<a*b-a-b<<'\n';
19     return 0;
20 }
21 //

 

Guess you like

Origin www.cnblogs.com/leprechaun-kdl/p/11100524.html