【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);
    }
}
相关推荐
zyl7655 小时前
FlashAttention 详解:从 GPU 硬件、普通 Attention 到分块计算与 Online Softmax
算法
爱读书的小胖9 小时前
LeetCode 122:买卖股票的最佳时机 II(C)解题分析
算法
结局无敌9 小时前
React Native for OpenHarmony 实战:三方库 react-native-modal-dialog 的鸿蒙化适配指南
深度学习·算法·react native·react.js·harmonyos
OPEN-F9 小时前
ROS2系列教程:上位机建图与导航(原理综合)
算法·机器人
weixin_307779139 小时前
C++代码实现MATLAB中的fitrtree函数功能
开发语言·c++·算法·matlab
AI wins10 小时前
c++新增頭文件
c++
Shadow(⊙o⊙)10 小时前
仿muduo实现高并发服务器——事件就绪管理Channel.hpp
服务器·c++
tomwang032210 小时前
路径优化建模、优化算法分类及工程化小结
算法·数学建模·分类
小羊没烦恼!10 小时前
Ajax与JSON的一些总结
android·java·前端·数据库·mysql·算法·okhttp
by2099910 小时前
哈希表——快速找到数据:冲突、删除与扩容的实现
数据结构·c++·哈希算法·散列表