【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);
    }
}
相关推荐
阿猿收手吧!33 分钟前
【C++复习】C++特殊类总结
c++·单例模式
杭电码农-NEO38 分钟前
【C++拓展(四)】秋招建议与心得
开发语言·c++·求职招聘
计信猫1 小时前
从零开学C++:二叉搜索树
数据结构·c++·算法
循环渐进Forward1 小时前
【C++笔试强训】如何成为算法糕手Day1
数据结构·c++·算法·力扣·笔试·牛客
软行1 小时前
LeetCode 每日一题 最佳观光组合
c语言·数据结构·算法·leetcode
抓哇能手1 小时前
王道408考研数据结构-串-第四章
数据结构·考研·算法·408·王道408
Gu Gu Study1 小时前
【用Java学习数据结构系列】对象的比较(Priority Queue实现的前提)
数据结构·算法·排序算法
会有黎明吗1 小时前
Leetcode 162.寻找峰值
数据结构·算法·leetcode
激昂~逐流1 小时前
尊享面试100题
数据结构·算法·面试
Navigator_Z1 小时前
LeetCode //C - 386. Lexicographical Numbers
c语言·算法·leetcode