Nyoj-integer property (Extended Euclidean)

Source: Internet
Author: User
Integer Nature Time Limit: 500 MS | memory limit: 65535 kb difficulty: 1
Description

We know that in mathematics, for any two positive integers A and B, there must be a pair of integers S and T so that SA + TB = gcd (A, B ).

Input
Multiple groups of test data.
Enter two non-negative integers A and B in each group, and a + B> 0 and A is not equal to B.
0 <= A, B <100000.
Output
Output S and T that meet the conditions.
Sample Input
2 43 8737 635
Sample output
1 03 -1193 -224
Code:
#include<stdio.h>void EXGCD(int a,int b,int &x,int &y){if(b==0){x=1;y=0;return ;}    EXGCD(b,a%b,x,y);int tem;tem=x;x=y;y=tem-a/b*y;}int main(){int a,b,x,y;while(~scanf("%d%d",&a,&b)){EXGCD(a,b,x,y);printf("%d %d\n",x,y);}return 0;}

Nyoj-integer property (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.