Codeforces Beta Round #7 C. Line Exgcd
C. Line
题目连接:
http://www.codeforces.com/contest/7/problem/C
Description
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 A, B and C ( - 2·109 ≤ A, B, C ≤ 2·109) — corresponding coefficients of the line equation. It is guaranteed that A2 + B2 > 0.
Output
Output the sequence of lines. Each line should contain either the result of alloc operation procession , or ILLEGAL_ERASE_ARGUMENT as a result of failed erase operation procession. Output lines should go in the same order in which the operations are processed. Successful procession of alloc operation should return integers, starting with 1, as the identifiers of the allocated blocks.
Sample Input
2 5 3
Sample Output
6 -3
Hint
题意
给你一条直线,让你找出直线上的一个整数点,不存在输出-1
题解:
exgcd裸题
求一下ax+by=gcd(a,b)的x,y之后,再check一下-c%gcd(a,b)是否等于0就好了,不等于0,那就输出-1
否则就怼一波。
代码
#include<bits/stdc++.h>
using namespace std;
void gcd(long long a,long long b,long long& d,long long& x,long long& y)
{
if(!b){d=a,x=1,y=0;}
else{gcd(b,a%b,d,y,x);y-=x*(a/b);}
}
int main()
{
long long a,b,c,d,x,y;
cin>>a>>b>>c;c=-c;
gcd(a,b,d,x,y);
if(c%d!=0)return puts("-1"),0;
else
{
printf("%lld %lld\n",x*c/d,y*c/d);
}
}
Codeforces Beta Round #7 C. Line Exgcd的更多相关文章
- Codeforces Beta Round #7 C. Line (扩展欧几里德)
题目链接:http://codeforces.com/problemset/problem/7/C 给你一个直线方程,有整数解输出答案,否则输出-1. 扩欧模版题.这里有讲解:http://www.c ...
- Codeforces Beta Round #32 (Div. 2, Codeforces format)
Codeforces Beta Round #32 (Div. 2, Codeforces format) http://codeforces.com/contest/32 A #include< ...
- Codeforces Beta Round #5 B. Center Alignment 模拟题
B. Center Alignment 题目连接: http://www.codeforces.com/contest/5/problem/B Description Almost every tex ...
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
- Codeforces Beta Round #62 题解【ABCD】
Codeforces Beta Round #62 A Irrational problem 题意 f(x) = x mod p1 mod p2 mod p3 mod p4 问你[a,b]中有多少个数 ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
- Codeforces Beta Round #13 C. Sequence (DP)
题目大意 给一个数列,长度不超过 5000,每次可以将其中的一个数加 1 或者减 1,问,最少需要多少次操作,才能使得这个数列单调不降 数列中每个数为 -109-109 中的一个数 做法分析 先这样考 ...
- Codeforces Beta Round #79 (Div. 2 Only)
Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...
- Codeforces Beta Round #77 (Div. 2 Only)
Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...
随机推荐
- [Leetcode] Sum 系列
Sum 系列题解 Two Sum题解 题目来源:https://leetcode.com/problems/two-sum/description/ Description Given an arra ...
- 程序调试命令gdb
锁定线程 set scheduler-locking 1.要使用此命令,先用gcc -g编译程序,如: $gcc -g test.c -o test 编译test.c源程序,输入此程序的调试版本t ...
- android 动态改变控件位置和大小 .
动态改变控件位置的方法: setPadding()的方法更改布局位置. 如我要把Imageview下移200px: ImageView.setPadding( ImageVie ...
- jquery如何获取第一个或最后一个子元素
jquery如何获取第一个或最后一个子元素? 通过children方法,children("input:first-child") $(this).children(" ...
- LightOJ 1319 Monkey Tradition(中国剩余定理)
题目链接:https://vjudge.net/contest/28079#problem/U 题目大意:给你n(n<12)行,每行有pi,ri,求一个数ans满足ans%pi=ri(i从1~n ...
- pandas 数据结构的基本功能
操作Series和DataFrame中的数据的常用方法: 导入python库: import numpy as np import pandas as pd 测试的数据结构: Series: > ...
- Go语言入门之指针的使用
指针的使用: package main import "fmt" func zhi(){ a:= var b *int=&a //声明指针并赋值 *b=3 //改变内存地址 ...
- oracle去掉字段值中的某些字符串
我想去掉字段值中的“_” select replace(fdisplayname,'_','') from SHENZHENJM1222.B replace 第一个参数:字段/值,第二个参数时替换字符 ...
- Codeforces Round #492 (Div. 2) [Thanks, uDebug!]
这次的题好奇怪哦... C - Tesla 思路:先把跟停车位相邻的车停进去,然后开始转圈... #include<bits/stdc++.h> #define LL long long ...
- python网页下载
python 2.7版本下可以运行 import urllib2 def getHtml(url): response = None requset = None headers = {'User-A ...