[NOIP2012 Improvement Group] Codevs 1200 with congruence (extended Euclidean algorithm)

Source: Internet
Author: User
Tags gcd

Number of topics: All number theory is disgusting to me. Don't want to say anything more.

------------------------------------------------

#include <iostream> using namespace std; void gcd (int a,int b,int &x,int &y) {if (!b) {x=1; y=0;}else {GCD (B,a%b,x,y);int t=x; X=y;Y=t-a/b*x;}} int main () {//Freopen ("Test.in", "R", stdin);//Freopen ("Test.out", "w", stdout);int a,b,x,y;cin>>a>>b;GCD (A,b,x,y);cout<< (x%b+b)%b<<endl; return 0;}

------------------------------------------------

1200 congruence equation

2012 Noip National League Improvement Group

time limit: 1 s space limit: 128000 KB   Title level: Diamonds Diamond Solving


Title Description Description

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

Enter a description input Description

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

outputs description 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 to sample

3 10

Sample output Sample outputs

7

data size & Hint

"Data Range"
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

[NOIP2012 Improvement Group] Codevs 1200 with congruence (extended Euclidean algorithm)

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.