HDU 2669 romantic (Extended Euclidean)

Source: Internet
Author: User

Question link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 2669


Problem descriptionthe sky is Sprite.
The birds is fly in the sky.
The wind is wonderful.
Blew throw the trees
Trees are shaking, leaves are falling.
Lovers walk passing, and so are you.
........................ Write in English class by yifenfei

 

Girls are clever and bright. In HDU every girl like math. Every girl like to solve math problem!
Now tell you two nonnegative integer A and B. Find the nonnegative integer x and integer y to satisfy x * A + y * B = 1. If no such answer print "sorry" instead.
 
Inputthe input contains multiple test cases.
Each case two nonnegative integer a, B (0 <a, B <= 2 ^ 31)
 
Outputoutput nonnegative integer x and integer y, if there are more answers than the X smaller one will be choosed. If no answer put "sorry" instead.
 
Sample Input
77 5110 4434 79
 
Sample output
2 -3sorry7 -3
 
Authoryifenfei
Sourcehdu girls' session Open-who said women are not as good as men?

PS:

Extended Euclidean template questions;

Appendix: Extended Euclidean explanation: http://blog.csdn.net/u012860063/article/details/39760003

The Code is as follows:

# Include <cstdio> # include <cstring> # include <cmath> typedef _ int64 ll; ll exgcd (ll a, LL B, ll & X, ll & Y) {If (B = 0) {x = 1; y = 0; return a;} else {ll r = exgcd (B, A % B, x, y ); ll T = x; X = y; y = T-A/B * Y; return r ;}int main () {ll a, B, X, Y; while (scanf ("% i64d % i64d", & A, & B )! = EOF) {ll d = exgcd (a, B, x, y); If (1% d) // printf ("Sorry \ n") cannot be divisible "); else {While (x <0) x + = B, Y-= A; printf ("% i64d % i64d \ n", x, y) ;}} return 0 ;}


HDU 2669 romantic (Extended Euclidean)

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.