HDU 1792 a new change problem (mathematical law questions, number theory knowledge)

Source: Internet
Author: User
A new change problem

Time Limit: 5000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 533 accepted submission (s): 265

Problem descriptionnow given two kinds of coins a and B, which satisfy that gcd (a, B) = 1. here you can assume that there are enough coins for both kinds. please calculate the maximal value that you cannot pay and the total number that you cannot pay.

 

Inputthe input will consist of a series of pairs of integers A and B, separated by a space, one pair of integers per line.

 

Outputfor each pair of input integers A and B you shoshould output the maximal value that you cannot pay and the total number that you cannot pay, and with one line of output for each line in input.

 

Sample input2 3 3 4

 

Sample output1 1 5 3

 

Authorlcy

 

The recommendlcy question is to give two mutually qualitative numbers A and B. A * x + B * Y (x> = 0, Y> = 0) Ask the maximum number that cannot be expressed, and the number that cannot be expressed. Number theory knowledge; number is (A-1) * (B-1)/2; the maximum cannot represent the number is a * B-A-B; all the number can be divided into Class, the remainder of A is 0 ~ A-1. · For brief derivation, see: http://hi.baidu.com/qq258513813/blog/item/81c1d5c57e9ac7009d163da6.html Code :
 # include 
   
   
int main ()
{< br> int A, B;
while (scanf ( " % d " , & A, & B )! = EOF)
{< br> printf ( " % d \ n " , A * B-A-B, (A- 1 ) * (B- 1 )/ 2 );
}< br> return 0 ;< BR >}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.