Codeforces 7c Line (extended Euclidean)

Source: Internet
Author: User
Tags integer numbers

C. Line

A line on the plane are described by an equation Ax + by + C = 0. Whose coordinates is integer numbers from -5 10- 5 10-Inc-- Lusive, or to the find out such points does not exist.


The first line contains three integers a, B and C ( -2 109≤ a, C9>b, C ≤2 109)-corresponding coefficients of the line equation. It's guaranteed that A2 + B2 > 0.


If the required point exists, output its coordinates, otherwise output -1.

Sample Test (s) input
2 5 3

1#include <cstdio>2#include <cstring>3 using namespacestd;4 5 voidEXGCD (intAintBint& D,Long Long& X,Long Long&y)6 {7     if(!b) d=a,x=1, y=0;8     Else9     {TenEXGCD (b,a%b,d,y,x); OneY-=x* (A/b); A     } - } -  the intMain () - { -     inta,b,c; -      while(SCANF ("%d%d%d", &a,&b,&c)! =EOF) +     { -         intDLong Longx, y; + EXGCD (a,b,d,x,y); A         if(c%d!=0) atPuts"-1"); -         Else -         { -x*=c/D; -y*=c/D; -printf"%lld%lld\n",-x,-y); in         } -     } to     return 0; +}

Codeforces 7c Line (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: 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.