codeforces 7c line(扩展欧几里得)

C. Line

A line on the plane is described by an equation Ax + By + C = 0. You are to find any point on this line, whose coordinates are integer numbers from  - 5·1018 to 5·1018 inclusive, or to find out that such points do not exist.

Input

The first line contains three integers AB and C ( - 2·109 ≤ A, B, C ≤ 2·109) — corresponding coefficients of the line equation. It is guaranteed that A2 + B2 > 0.

Output

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

Sample test(s)

input

2 5 3

output

6 -3
 1 #include<cstdio>
 2 #include<cstring>
 3 using namespace std;
 4
 5 void exgcd(int a,int b,int& d,long long& x,long long& y)
 6 {
 7     if(!b)d=a,x=1,y=0;
 8     else
 9     {
10         exgcd(b,a%b,d,y,x);
11         y-=x*(a/b);
12     }
13 }
14
15 int main()
16 {
17     int a,b,c;
18     while(scanf("%d%d%d",&a,&b,&c)!=EOF)
19     {
20         int d;long long x,y;
21         exgcd(a,b,d,x,y);
22         if(c%d!=0)
23             puts("-1");
24         else
25         {
26             x*=c/d;
27             y*=c/d;
28             printf("%lld %lld\n",-x,-y);
29         }
30     }
31     return 0;
32 }
时间: 2024-10-10 04:07:51

codeforces 7c line(扩展欧几里得)的相关文章

[codeforces 200 E Tractor College]枚举,扩展欧几里得,三分

题目出自 Codeforces Round #126 (Div. 2) 的E. 题意大致如下:给定a,b,c,s,求三个非负整数x,y,z,满足0<=x<=y<=z,ax+by+cz=s,使得f(x,y,z)=|ax-by|+|by-cz|最小 思路:枚举z,得到一个方程ax+by=s-cz,用扩展欧几里得求出这个方程的一个解,然后三分通解的整系数,求出最小f值.至于为什么可以三分画画图就清楚了,两个绝对值函数叠加在一起最多只有三种状态(第一维表示临界点较小的那个绝对值函数):(降,降)

【数论】【扩展欧几里得】Codeforces 710D Two Arithmetic Progressions

题目链接: http://codeforces.com/problemset/problem/710/D 题目大意: 两个等差数列a1x+b1和a2x+b2,求L到R区间内重叠的点有几个. 0 < a1, a2 ≤ 2·109,  - 2·109 ≤ b1, b2, L, R ≤ 2·109, L ≤ R). 题目思路: [数论][扩展欧几里得] 据题意可得同余方程组 x=b1(mod a1) 即 x=k1*a1+b1 x=b2(mod a2) x=k2*a2+b2 化简,k1*a1=k2*a2

[ACM] hdu 3923 Invoker (Poyla计数,高速幂运算,扩展欧几里得或费马小定理)

Invoker Problem Description On of Vance's favourite hero is Invoker, Kael. As many people knows Kael can control the elements and combine them to invoke a powerful skill. Vance like Kael very much so he changes the map to make Kael more powerful. In

UVA 10090 Marbles(扩展欧几里得)

Marbles Input: standard input Output: standard output I have some (say, n) marbles (small glass balls) and I am going to buy some boxes to store them. The boxes are of two types: Type 1: each box costs c1 Taka and can hold exactly n1 marbles Type 2:

POJ2115(扩展欧几里得)

C Looooops Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 23700   Accepted: 6550 Description A Compiler Mystery: We are given a C-language style for loop of type for (variable = A; variable != B; variable += C) statement; I.e., a loop w

[ACM] hdu 3923 Invoker (Poyla计数,快速幂运算,扩展欧几里得或费马小定理)

Invoker Problem Description On of Vance's favourite hero is Invoker, Kael. As many people knows Kael can control the elements and combine them to invoke a powerful skill. Vance like Kael very much so he changes the map to make Kael more powerful. In

【POJ 2891】Strange Way to Express Integers(扩展欧几里得)

[POJ 2891]Strange Way to Express Integers(扩展欧几里得) Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 12934   Accepted: 4130 Description Elina is reading a book written by Rujia Liu, which introduces a strange way to express non-negative in

POJ - 2115 - C Looooops (扩展欧几里得)

C Looooops Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 19826   Accepted: 5299 Description A Compiler Mystery: We are given a C-language style for loop of type for (variable = A; variable != B; variable += C) statement; I.e., a loop w

UVa 11768 格点判定(扩展欧几里得求线段整点)

https://vjudge.net/problem/UVA-11768 题意: 给定两个点A(x1,y1)和B(x2,y2),均为0.1的整数倍.统计选段AB穿过多少个整点. 思路: 做了这道题之后对于扩展欧几里得有了全面的了解. 根据两点式公式求出直线 ,那么ax+by=c 中的a.b.c都可以确定下来了. 接下来首先去计算出一组解(x0,y0),因为根据这一组解,你可以写出它的任意解,其中,K取任何整数. 需要注意的是,这个 a' 和 b' 是很重要的,比如说 b' ,它代表的是x每隔 b