Codeforces Beta Round #7 C. Line 扩展欧几里德
1 second
256 megabytes
standard input
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.
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.
If the required point exists, output its coordinates, otherwise output -1.
2 5 3
6 -3思路:简单的扩展欧几里德,就是b==0的情况小心点;
#include<iostream> #include<cstdio> #include<cmath> #include<string> #include<queue> #include<algorithm> #include<stack> #include<cstring> #include<vector> #include<list> #include<set> #include<map> #define true ture #define false flase using namespace std; #define ll __int64 #define inf 0xfffffff int scan() {int res = 0 , ch ;while( !( ( ch = getchar() ) >= '0' && ch <= '9' ) ){if( ch == EOF ) return 1 << 30 ;}res = ch - '0' ;while( ( ch = getchar() ) >= '0' && ch <= '9' )res = res * 10 + ( ch - '0' ) ;return res ; } ll gcd(ll x,ll y) {return x%y==0?y:gcd(y,x%y); } void extend_Euclid(ll a, ll b, ll &x, ll &y) {if(b == 0){x = 1;y = 0;return;}extend_Euclid(b, a % b, x, y);ll tmp = x;x = y;y = tmp - (a / b) * y; } int main() {ll a,b,c,x,y;cin>>a>>b>>c;c=-c;if(b==0){if(c%a==0){cout<<c/a<<" 0"<<endl;}elsecout<<"-1"<<endl;return 0;}ll gg=gcd(a,b);if(c%gg==0){extend_Euclid(a,b,x,y);cout<<c/gg*x<<" "<<c/gg*y<<endl;}elsecout<<"-1"<<endl;return 0; }
View Code
转载于:https://www.cnblogs.com/jhz033/p/5458358.html
Codeforces Beta Round #7 C. Line 扩展欧几里德相关推荐
- Codeforces Beta Round #7 C. Line (扩展欧几里德)
题目链接:http://codeforces.com/problemset/problem/7/C 给你一个直线方程,有整数解输出答案,否则输出-1. 扩欧模版题.这里有讲解:http://www.c ...
- Codeforces Beta Round #7
Codeforces Beta Round #7 http://codeforces.com/contest/7 A 水题 1 #include<bits/stdc++.h> 2 usin ...
- 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 1
codeforces beta round 1 A Theatre Square in the capital city of Berland has a rectangular shape with ...
- Codeforces Beta Round #17 D. Notepad (数论 + 广义欧拉定理降幂)
Codeforces Beta Round #17 题目链接:点击我打开题目链接 大概题意: 给你 \(b\),\(n\),\(c\). 让你求:\((b)^{n-1}*(b-1)\%c\). \(2 ...
- Codeforces Beta Round #75 (Div. 1 Only) B. Queue 线段树。单点更新
http://codeforces.com/problemset/problem/91/B 题意: 给你n个数,求得i 到n中小于a[i]的最右边的a[j],然后求a[i]到a[j]之间包含了多少个数 ...
- Codeforces Beta Round #51 D. Beautiful numbers 数位dp + 状态优化
传送门 文章目录 题意: 思路: 题意: 思路: 数位dpdpdp挺经典的一个题辣,有一个很明显的状态就是f[pos][num][lcm]f[pos][num][lcm]f[pos][num][lcm ...
- Codeforces Beta Round #22 (Div. 2 Only) E. Scheme(DFS+强连通)
题目大意 给了 n(2<=n<=105) 个点,从每个点 u 出发连向了一个点 v(共 n 条边) 现在要求添加最少的边使得整个图是一个强连通图 做法分析 这道题千万不要一般化:先求强连通 ...
- Codeforces Beta Round #4 (Div. 2 Only)
Codeforces Beta Round #4 (Div. 2 Only) A 水题 1 #include<bits/stdc++.h> 2 using namespace std; 3 ...
最新文章
- 机器学习中的梯度下降( Gradient Descent)算法
- C++ map详细介绍
- 机器学习:一步步教你理解反向传播方法
- SpringMvc-Httl-shiro的整合
- github 使用总结-----转
- python Celery 分布式任务队列快速入门
- linux编程:getenv,putenv,setenv
- kaggle(一)训练猫狗数据集
- WebAPI(part2)--获取元素
- flutter 图解_【Flutter 专题】83 图解自定义 ACEWave 波浪 Widget (一)
- 深度学习在医疗方面的应用 精准医学受追捧
- apache netbeans ide为什么安装不了_Eclipse安装及常见的基于Eclipse的嵌入式集成开发环境...
- golang 大数据平台_一文读懂数据平台、大数据平台、数据中台
- sprintf_s用法c语言,sprintf_s函数的使用
- H3CSE园区-LLDP技术
- 笔记——关于每次重启之后,虚拟机网络无网络访问权限的解决方法
- 关于幼儿教师音乐素养对幼儿成长影响力的研究的论文怎么写呀
- 学习Java的你知道什么是程序思维?
- “一见钟情” 文证通证件识别让旅行证件不再寂寞
- PB 切换中英文输入法
热门文章
- 一种非常好用的图像处理软件
- 卷积神经网络对咖啡病虫害识别和分割(分割+分类,病害严重程度详细)
- oracle有几种类型表空间,oracle 数据创建时如何指定表空间类型
- canvas插件_HTML系列之-HTML5新元素之Canvas详解
- intel x520网卡驱动_手工编译linux桌面内核(二)——硬件驱动的配置 下篇
- android 数据持久化——I/O操作
- 删除“ie8左侧收藏夹图标(黄星星)”及“恢复”的方法
- c语言蓝桥删除多余的括号,蓝桥杯 括号问题
- 圣杯布局——针对前端小白篇
- data自定义属性获取方法和设置