HDU-2669 拓展欧几里得
来源:互联网 发布:天猫和淘宝是什么关系 编辑:程序博客网 时间:2024/06/05 08:21
题目一大推 其实都没用,昨天训练赛看到a*x+b*y= 1;就想到了拓展欧几里得,直接写就可以,在取结果的时候注意,需要x = (x % b + b)%b ; 防负数就可以了
昨天写这个模板还是写的有点慢~~还需要更加熟练
Girls are clever and bright. In HDU every girl like math. Every girl like to solve math problem!
Now tell you two nonnegative integer a and b. Find the nonnegative integer X and integer Y to satisfy X*a + Y*b = 1. If no such answer print "sorry" instead.
Each case two nonnegative integer a,b (0<a, b<=2^31)
77 5110 4434 79
#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <algorithm>#include <vector>#include <map>#include <math.h>#include <stack>#define LL long longusing namespace std;const int INF = 0x3f3f3f3f;int dir[4][2] = {{1,0},{0,1},{-1,0},{0,-1}};LL exgcd(LL n ,LL m,LL &x,LL &y){ if (m == 0) { x = 1; y = 0; return n; } LL g = exgcd(m, n % m, x, y); LL t = x - n / m * y; x = y; y = t; return g;}int main(){ LL a,b,x,y; while(cin>>a>>b) { LL d = exgcd(a,b,x,y); if(1 % d) cout<<"sorry"<<endl; else { x=(x%b+b)%b; y=(1-a*x)/b; cout<<x<<" "<<y<<endl; } } return 0;}
阅读全文
0 0
- hdu 2669(拓展欧几里得)
- HDU-2669 拓展欧几里得
- HDU 2669 Romantic(拓展欧几里得)
- HDU 2669 Romantic 拓展欧几里得模板题
- hdu 1576 拓展欧几里得
- hdu 1576(拓展欧几里得)
- HDU-1211(RSA)-拓展欧几里得
- HDU 1576 A/B(拓展欧几里得)
- HDU 1576 A/B(拓展欧几里得)
- 拓展欧几里得 HDU 1576 A/B
- HDU-1576(A/B)拓展欧几里得
- 拓展欧几里得
- 拓展欧几里得
- 拓展欧几里得
- 拓展欧几里得
- 拓展欧几里得
- 拓展欧几里得
- 拓展欧几里得
- cf 304A Pythagorean Theorem II
- Swift 路由机制设计
- 我眼中的ASP.NET Core之微服务
- Python 实现 Discuz论坛附件下载权限绕过漏洞
- ReactiveCocoa源码解析(四) Signal中的静态属性静态方法以及面向协议扩展
- HDU-2669 拓展欧几里得
- 公司员工考勤系统Java代码
- Caffe3——ImageNet数据集创建lmdb类型的数据
- hdu—3342 Legal or Not 拓扑图的搜索
- 我该如何在30天后找到一份数据挖掘相关工作
- 使用Leap Motion Orion开发酷炫的手势识别VR/AR应用
- win10(1703)应用商店下载应用提示错误代码0x80D0000A
- 下拉刷新上拉加载
- QML自定义标题栏