CodeForces 7C
来源:互联网 发布:python 读取文件类型 编辑:程序博客网 时间:2024/05/16 19:20
链接:点击打开链接
题意:求Ax+By=c中x,y的值,无解时输出-1
代码:
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespace std;long long x,y;long long gcd(long long a,long long b){ if(b==0) return a; return gcd(b,a%b);}void ex_gcd(long long a,long long b){ long long t; if(b==0){ x=1;y=0; return; } ex_gcd(b,a%b); //扩展欧几里得模板 t=x;x=y;y=t-(a/b)*x;}int main(){ long long a,b,c,d; while(cin>>a>>b>>c){ d=gcd(a,b); if(c%d){ //互质的时候无解 cout<<"-1"<<endl; continue; } a/=d;b/=d;c/=d; ex_gcd(a,b); c=-c; x*=c;y*=c; cout<<x<<" "<<y<<endl; } return 0;}
0 0
- CodeForces 7C
- CodeForces 7C - Line
- Codeforces 7C
- CodeForces 7C 【数论】
- codeforces 7C Line
- CodeForces 7C【扩展欧几里得】
- Codeforces-340-C(c++)
- Codeforces-507-C(c++)
- CodeForces 731C C
- CodeForces-612C C
- CodeForces 7C Line (扩展欧几里得)
- codeforces 7C 【扩展欧几里得算法】
- CodeForces 7 C. Line(扩展欧几里得)
- CodeForces 7C(扩展欧几里德解方程)
- CodeForces 7C Line Exgcd(数论)
- codeforces 7C Line 扩展欧几里德 Java
- CodeForces 7C Line Exgcd(数论)
- Codeforces 7C Line(拓展欧几里得)
- IOS 多线程 RUNLOOP 机制 (一)
- 卷积神经网络CNN
- SQL语句的划分--SQL笔记
- @AssociationOverrides @AttributeOverride @AttributeOverride
- cocos2dx toLua 没有PyYAML的解决办法
- CodeForces 7C
- POJ 2535 Very Simple Problem(水~)
- JavaScript设计模式
- 黑马程序员-IOS学习笔记 用指针逆序一个数组
- MySQL系统表
- 小贝_mysql view视图学习
- IOS 多线程 RUNLOOP 机制 (二)
- GCD编程-串行队列与并发队列
- puppet安装和部署