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 ...
随机推荐
- php文件上传——php经典实例
php文件上传——php经典实例 表单页 <html> <head> <title>文件上传</title> <meta charset='ut ...
- [004] last_k_node
[Description] find the k-th node from the last node of single linked list. e.g. Linked-list: 1-2-3-4 ...
- Django 1.10文档中文版Part2
目录 2.5 第一个Django app,Part 3:视图和模板 2.5.1 概览 2.5.2 编写更多的视图 2.5.3 编写能实际干点活的视图 2.5.4 404错误 2.5.5 使用模板系统 ...
- 查看wtmp(登陆信息的内容)
/var/log/wtmp文件的作用 /var/log/wtmp也是一个二进制文件,记录每个用户的登录次数和持续时间等信息. 查看方法: 可以用last命令输出当中内容: debi ...
- 使用Guava retryer优雅的实现接口重试机制
转载自: 使用Guava retrying优雅的实现接口重调机制 Guava retrying:基于 guava 的重试组件 实际项目中,为了考虑网络抖动,加锁并发冲突等场景,我们经常需要对异常操作进 ...
- CSU 1102 多连块拼图
多连块拼图 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 多连块是指由多个等大正方形边与边连接而成的平面连通图形. ———— 维基百科 ...
- lr总结
最近一直在用Loardrunner做性能测试,记录下自己在工作中遇到的问题. LR的基本设置 首先是录制,在录制前选择TOOLS-recording options 在General中选择record ...
- php、mysql编译配置
与apache一起使用: Configure Command => './configure' '--prefix=/home/sujunjie/local/php' '--with-apx ...
- 今日头条、Face++开发岗面经
今日头条.Face++开发岗面经 [头条] 两个栈实现一个队列.怎么优化 数组每一个元素找出数组右边第一个大于自己的数 实现LRU TCP四次握手 滑动窗口.窗口大小 线程与进程区别 什么是线程安全 ...
- python 类继承
#!/usr/bin/python # Filename: inherit.py class SchoolMember: '''Represents any school member.''' def ...