【扩展欧几里得】Codevs 1200: [noip2012]同余方程
2024-08-27 12:28:23
Description
求关于 x 同余方程 ax ≡ 1 (mod b)的最小正整数解。
Input Description
输入只有一行,包含两个正整数 a, b,用 一个 空格隔开。
Output Description
输出只有一行包含一个正整数x0,即最小正整数解,输入数据保证一定有解。
裸的exgcd,不多讲了。。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm> typedef long long ll; using namespace std; ll x,y; void exgcd(ll a,ll b)
{
if(b==)
{
x=;
y=;
return;
}
exgcd(b,a%b);
ll
sb=x;
x=y;
y=sb-(a/b*y);
} void solve(ll a,ll b)
{
exgcd(a,b);
printf("%lld",(x+b)%b);//最小正整数解
} int main()
{
ll a,b;
scanf("%lld%lld",&a,&b);
solve(a,b);
return ;
}
最新文章
- 在DirectShow中支持DXVA 2.0(Supporting DXVA 2.0 in DirectShow)
- Vue.js之v-for
- Nodejs express 文件上传
- 完美C++(第5版)(双色)
- C# sql语句拼接时 like情况的防sql注入的用法
- C语言面试题(二)
- SDAutoLayout:比masonry更简单易用的自动布局库
- 复制中的NOT FOR REPLICATION
- 360每日自动签到,领取积分 (java httpclient4.x)
- Introducing RecyclerView(一)
- hdu2429Ping pong
- [刷题]算法竞赛入门经典(第2版) 5-15/UVa12333 - Revenge of Fibonacci
- java基础---字符串string
- Vuex 源码学习(一)
- Switch-case 内定义变量的问题
- 关于python中的operator.itemgetter()函数的用法
- CSS简单使用
- NopCommerce用.net core重写ef
- Python实现文字聊天室
- 01c语言基础