Codeforces Beta Round #7 C. Line (Extended Euclid)

Source: Internet
Author: User

Title Link: Http://codeforces.com/problemset/problem/7/C

give you a linear equation with an integer solution to output the answer, otherwise output-1.

Expansion of the European template problem. Here are the explanations: http://www.cnblogs.com/Recoder/p/5459812.html

(Long time no write EXGCD, will not write)

1#include <bits/stdc++.h>2 using namespacestd;3typedefLong LongLL;4 5ll EXGCD (ll A, ll B, ll &x, LL &y) {6LL res =A;7     if(!b) {8x =1, y =0;9     }Ten     Else { Oneres = EXGCD (b, a%b, x, y); ALL temp =x; -x =y; -y = temp-a/b *y; the     } -     returnRes; - } -  + intMain () - { + LL A, B, C, GCD, X, y; ACin >> a >> b >>C; atGCD =EXGCD (A, B, X, y); -     if(c% GCD = =0) { -LL temp =-C/gcd; -cout << x * Temp <<" "<< y * Temp <<Endl; -     } -     Else { incout <<-1<<Endl; -     } to}

Codeforces Beta Round #7 C. Line (Extended Euclid)

Related Article

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.