zoukankan      html  css  js  c++  java
  • C. Line (扩展欧几里得)

    C. Line
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    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.

    Examples
    input
    Copy
    2 5 3
    output
    Copy
    6 -3

    ax+by+c=0,化为ax+by=-c/gcd(a,b)*gcd(a,b),

    套拓展欧几里得就可以解出了

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 const int maxn = 1e5 + 10;
     4 const int mod = 1e9 + 7;
     5 typedef long long LL;
     6 LL exgcd(LL a, LL b, LL &x, LL &y) {
     7     if (b == 0) {
     8         x = 1, y = 0;
     9         return a;
    10     }
    11     LL g = exgcd(b, a % b, x, y);
    12     LL t;
    13     t = x, x = y, y = t - (a / b) * y;
    14     return g;
    15 }
    16 int main() {
    17     LL a, b, c, x, y;
    18     cin >> a >> b >> c;
    19     LL t = exgcd(a, b, x, y);
    20     if (c % t == 0) printf("%lld %lld
    ", -x * c / t, -y * c / t);
    21     else printf("-1
    ");
    22     return 0;
    23 }
  • 相关阅读:
    spring 包的依赖关系
    菜鸟程序猿之IDEA快捷键
    eclipse的svn插件
    SVN使用教程总结
    Oracle 11g安装步骤详谈
    C3P0连接池的配置与使用
    Java课程设计
    201621123057 《Java程序设计》第14周学习总结
    201621123057 《Java程序设计》第13周学习总结
    201621123057 《Java程序设计》第12周学习总结
  • 原文地址:https://www.cnblogs.com/qldabiaoge/p/9377422.html
Copyright © 2011-2022 走看看