【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);
    }
}
相关推荐
LXS_3572 小时前
Day 05 C++ 入门 之 指针
开发语言·c++·笔记·学习方法·改行学it
MicroTech20252 小时前
微算法科技(MLGO)研发突破性低复杂度CFG算法,成功缓解边缘分裂学习中的掉队者问题
科技·学习·算法
墨染点香3 小时前
LeetCode 刷题【126. 单词接龙 II】
算法·leetcode·职场和发展
aloha_7893 小时前
力扣hot100做题整理91-100
数据结构·算法·leetcode
Tiny番茄3 小时前
31.下一个排列
数据结构·python·算法·leetcode
挂科是不可能出现的3 小时前
最长连续序列
数据结构·c++·算法
前端小L4 小时前
动态规划的“数学之魂”:从DP推演到质因数分解——巧解「只有两个键的键盘」
算法·动态规划
RTC老炮4 小时前
webrtc弱网-ReceiveSideCongestionController类源码分析及算法原理
网络·算法·webrtc
mjhcsp4 小时前
C++ int 类型深度解析:从底层实现到实战应用
c++·int
21号 14 小时前
9.Redis 集群(重在理解)
数据库·redis·算法