Rokua P1082 congruence equation

Source: Internet
Author: User

Title Description

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

Input/output format

Input format:

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

Output format:

The output has only one row and contains a positive integer x0, which is the minimum positive integer solution. The input data guarantees that there must be a solution.

Input and Output Sample input example # #:
3 10
Sample # # of output:
7
Description

"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.

NOIP 2012 Raising group The first question of the second day

Basic application of Extended Euclidean algorithm

1#include <iostream>2#include <cstdio>3#include <algorithm>4#include <cmath>5 using namespacestd;6 intb;7 voidEXGCD (intAintBint&x,int&y) {8     if(b==0){9x=1; y=0;Ten         return; One     } AEXGCD (b,a%b,x,y); -     intt=x;x=y;y=t-a/b*y; - } the intMain () { -scanf"%d%d",&a,&b); -     intx, y; - EXGCD (a,b,x,y); +x= (x%b+b)%b; -printf"%d\n", x); +     return 0; A}

Rokua P1082 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.