HDOJ-2669 Romantic(数论)
来源:互联网 发布:网络心理学的杂志 编辑:程序博客网 时间:2024/06/05 04:06
裸的扩展欧几里得算法,但要注意题目中要求a为非负数,扩展欧几里得算出来的a可能是负的,需要对a,b进行一下调整,否则会WA。
#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;typedef long long LL;LL Ex_gcd(LL a, LL b, LL &x, LL &y){LL d;if (a == 0 && b == 0) return -1;// 无GCDif (b == 0){x = 1;y = 0;return a;}d = Ex_gcd(b, a%b, y, x);y -= a / b * x;return d;}int main(){LL a, b, x, y;while (~scanf("%I64d%I64d", &a, &b)){if (Ex_gcd(a, b, x, y) != 1)printf("sorry\n");else{//注意解出来的x可能是负数,需要调整一下while (x<0){x += b;y -= a;}printf("%I64d %I64d\n", x, y);}}return 0;}
0 0
- HDOJ-2669 Romantic(数论)
- HDOJ 2669 Romantic
- hdoj-【2669 Romantic】
- HDOJ 2669 Romantic(exgcd裸题)
- HDOJ-----2669---Romantic扩展欧几里得
- [数论]HDU 2669 Romantic 扩展欧几里得算法
- HDOJ 2669 Romantic (扩展欧几里德)
- hdu 1576 A/B || hdu 2669 Romantic (数论--欧几里德)
- HDOJ 题目2669 Romantic(拓展的欧几里得,模板)
- hdoj 2669 Romantic 【扩展欧几里得 求解最小非负解】
- hdoj 2669 Romantic 【扩展欧几里得 求解最小非负解】
- HDOJ 4901 The Romantic Hero
- HDOJ 4901 - The Romantic Hero 简单dp
- HDU 2669 Romantic
- hdu 2669 C - Romantic
- hdu 2669 Romantic
- Romantic(hdu 2669)
- 【HDU】 2669 Romantic
- hdu5340 Three Palindromes(manacher算法)
- iOS面试题
- 矩阵的内涵
- CSS基础-22选择器-选择器详解(1)
- java中接口和抽象类
- HDOJ-2669 Romantic(数论)
- Linux 的启动流程(Debian发行版)
- Android事件分发详解
- 九度OJ 题目1010:A + B
- codevs第一次月赛A题
- 【effective c++读书笔记】【第4章】设计与声明(1)
- oracle 11g下载详述
- 基于OpenCV的人脸识别
- 线段树_HDU_4107