【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 分钟前
Android C++ 学习笔记3
android·c++
练习时长一年39 分钟前
Leetcode热题100(跳跃游戏 II)
算法·leetcode·游戏
小白菜又菜6 小时前
Leetcode 3432. Count Partitions with Even Sum Difference
算法·leetcode
wuhen_n7 小时前
LeetCode -- 15. 三数之和(中等)
前端·javascript·算法·leetcode
sin_hielo7 小时前
leetcode 2483
数据结构·算法·leetcode
Xの哲學8 小时前
Linux多级时间轮:高精度定时器的艺术与科学
linux·服务器·网络·算法·边缘计算
大头流矢8 小时前
归并排序与计数排序详解
数据结构·算法·排序算法
阿闽ooo8 小时前
外观模式:从家庭电源控制看“简化接口“的设计智慧
c++·设计模式·外观模式
油泼辣子多加9 小时前
【信创】算法开发适配
人工智能·深度学习·算法·机器学习
Aaron15889 小时前
AD9084和Versal RF系列具体应用案例对比分析
嵌入式硬件·算法·fpga开发·硬件架构·硬件工程·信号处理·基带工程