2012 Congruence equation

Source: Internet
Author: User

Congruence equation Title Description

The minimum positive integer solution for ax≡1 (mod b) of the x congruence equation is obtained.

Enter a description

Enter only one row, containing two positive integers a, b, separated by a space.

Output Description

The output has only one row containing a positive integer x0, or a minimum positive integer solution, and the input data guarantees there must be a solution.

Sample Input

3 10

Sample Output

7

data range and tips

For 40% of data, 2≤b≤1,000;
For 60% of data, 2≤b≤50,000,000
For 100% of data, 2≤a, b≤2,000,000,000

//the topic is a*x=1+b*y;//can be converted into A*x+b*y=1;//naked expansion of Euclid;//the time will be added to the positive;//B*x+a%b*y=1 = b*x+ (a-b* (A/b)) *y=1 =>a*y+b* (x (A/b) *y) =1;#include <cstdio>intA,b,x,y,ans;intEXGCD (intAintBint&x,int&y) {    if(b==0) {a=1; x=1; y=0;return 1;} intG=EXGCD (b,a%b,x,y), Z; Z=x;x=y;y=z-(A/b) *y; returnG;}intMain () {scanf ("%d%d",&a,&b); Ans=EXGCD (a,b,x,y);  while(x<0) x+=b; printf ("%d", x); return 0;}
View Code

2012 Congruence equation

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.