洛谷1082 同余方程
来源:互联网 发布:人生有涯而知无涯 编辑:程序博客网 时间:2024/06/05 07:41
标签:数论,扩展欧几里得
题目描述
求关于 x 的同余方程 ax ≡ 1(mod b)的最小正整数解。
输入输出格式
输入格式:
输入只有一行,包含两个正整数 a, b,用一个空格隔开。
输出格式:
输出只有一行,包含一个正整数 x0,即最小正整数解。输入数据保证一定有解。
输入输出样例
输入样例#1: 复制
3 10
输出样例#1: 复制
7
说明
【数据范围】
对于 40%的数据,2 ≤b≤1,000;
对于 60%的数据,2 ≤b≤50,000,000;
对于 100%的数据,2 ≤a, b≤2,000,000,000。
NOIP 2012 提高组 第二天 第一题
扩欧裸题
关于扩欧的证明https://www.zybuluo.com/samzhang/note/541890
Code
#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<algorithm>#define rep(i,a,b) for(int i=a;i<=b;i++)#define dep(i,a,b) for(int i=a;i>=b;i--)#define mem(x,num) memset(x,num,sizeof x)#define LL long longusing namespace std;inline LL read(){LL f=1,x=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;}LL a,b;void exgcd(int a,int b,LL &x,LL &y){if(b==0){x=1,y=0;return;}exgcd(b,a%b,x,y);LL t=x;x=y,y=t-a/b*y;}int main(){a=read(),b=read();LL x,y;exgcd(a,b,x,y);cout<<(x+b)%b<<endl;return 0;}
阅读全文
0 0
- 洛谷1082 同余方程
- 洛谷1082 同余方程
- 洛谷1082 同余方程
- 【NOIP2012】洛谷1082 同余方程
- 洛谷 1082 [NOIP2012] 同余方程 exgcd
- 洛谷 P1082 同余方程
- 洛谷_p1082同余方程
- 洛谷 P1082 同余方程
- [洛谷]P1082 同余方程
- 洛谷P1082 同余方程
- 洛谷P1082 同余方程
- 【NOIP2012】洛谷1082 同余方程 扩展欧几里得详解
- 洛谷 P1082 [NOIP2012 D2T1] 同余方程
- 线性同余方程
- 解同余方程
- 线性同余方程
- 线性同余方程
- 线性同余方程
- listagg( ) within group ( order by ) 与 wm_concat
- 关于openfire服务器启动变慢问题解决
- 其他题目---调整[0,x)区间上的数出现的概率
- Stencil Buffer&Stencil Test
- 用户管理系统模板
- 洛谷1082 同余方程
- fragment
- Node 调试指南 —— Inspector 协议
- 使用SpringCloud搭建微服务<二>---------创建微服务的消费者
- MyTask接口方法
- 跳转
- tomcat配置环境变量后在cmd中输入startup出现the JRE_HOME environment variable is not defined correctly This environ
- 综合2
- 一只想要进步的菜鸟