【HDU-2669 Romantic】

题目

Problem - 2669 (hdu.edu.cn)

代码

cpp 复制代码
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL ex_gcd(LL a, LL b, LL &x, LL &y)
{
    if (b == 0)
    {
        x = 1;
        y = 0;
        return a;
    }
    LL gcd = ex_gcd(b, a % b, x, y);
    LL temp;
    temp = x;
    x = y;
    y = temp - a / b * y;
    return gcd;
}
int main()
{
    LL a, b;
    while (scanf("%lld %lld", &a, &b) == 2)
    {
        LL x, y;
        LL gcd = ex_gcd(a, b, x, y);
        if (gcd != 1)
        {
            cout << "sorry\n";
            continue;
        }

        x = (x % b + b) % b;
        y = (1 - a * x) / b;
        printf("%ld %ld\n", x, y);
    }
}
相关推荐
嘴贱欠吻!2 小时前
Flutter鸿蒙开发指南(七):轮播图搜索框和导航栏
算法·flutter·图搜索算法
张祥6422889042 小时前
误差理论与测量平差基础笔记十
笔记·算法·机器学习
qq_192779873 小时前
C++模块化编程指南
开发语言·c++·算法
代码村新手3 小时前
C++-String
开发语言·c++
cici158745 小时前
大规模MIMO系统中Alamouti预编码的QPSK复用性能MATLAB仿真
算法·matlab·预编码算法
历程里程碑5 小时前
滑动窗口---- 无重复字符的最长子串
java·数据结构·c++·python·算法·leetcode·django
2501_940315266 小时前
航电oj:首字母变大写
开发语言·c++·算法
lhxcc_fly6 小时前
手撕简易版的智能指针
c++·智能指针实现
CodeByV6 小时前
【算法题】多源BFS
算法
TracyCoder1236 小时前
LeetCode Hot100(18/100)——160. 相交链表
算法·leetcode