caioj 1153 扩展欧几里德算法(解不定方程)
2024-08-30 06:17:59
模板题
注意exgcd函数要稍微记一下
#include<cstdio>
#include<cctype>
#include<algorithm>
#define REP(i, a, b) for(int i = (a); i < (b); i++)
#define _for(i, a, b) for(int i = (a); i <= (b); i++)
using namespace std;
void read(int& x)
{
int f = 1; x = 0; char ch = getchar();
while(!isdigit(ch)) { if(ch == '-1'); f = -1; ch = getchar(); }
while(isdigit(ch)) { x = x * 10 + ch - '0'; ch = getchar(); }
x *= f;
}
void exgcd(int a, int b, int& d, int& x, int& y)
{
if(!b) { d = a; x = 1; y = 0; }
else { exgcd(b, a % b, d, y, x); y -= x * (a / b); }
}
int main()
{
int a, b, c, x, y, d;
read(a), read(b), read(c);
exgcd(a, b, d, x, y);
if(c % d != 0) puts("no solution!");
else printf("%d %d\b", x * (c / d), y * (c / d));
return 0;
}
最新文章
- C# BitArray
- objective-c 通过类名实例化类
- JavaScript DOM实战:创建和克隆元素
- 学习macos常用的一些快捷键笔记
- Android学习5&mdash;布局简介
- iOS 数据持久性存储-对象归档
- 关闭Centos的自动更新
- MySql中PreparedStatement对象与Statement对象
- vb socket的使用
- 《java.util.concurrent 包源码阅读》26 Fork/Join框架之Join
- priority queue优先队列初次使用
- Vue-router重修01
- 【WebSocket No.3】使用WebSocket协议来做服务器
- anaconda新建虚拟环境安装各个依赖包
- python - class类 (五) 继承补充-子类继承父类属性/函数方法
- 用户人品预测大赛--getmax队--竞赛分享
- [watchdog]内核失败的重启方案
- Phpcms V9手机门户设置教程:怎么用PC V9做手机网站
- 微信QQ的二维码登录原理js代码解析
- 转载:IE下div使用margin:0px auto不居中的原因
热门文章
- Model、ModelMap和ModelAndView的使用详解
- 03 Winform基础
- javaScript(其他引用类型对象)
- CF449D Jzzhu and Numbers (状压DP+容斥)
- Linux red hat 核心版下安装Nginx
- Vue的数据依赖实现原理简析
- 《一个民企CEO的职场阳谋》–读书总结(上)
- Docker可视化管理工具对比(DockerUI、Shipyard、Rancher、Portainer)
- xftp和xshell的使用
- CF 567C(Geometric Progression-map)