欧几里得模板以及扩展欧几里得
来源:互联网 发布:mac os 10.6.8下载dmg 编辑:程序博客网 时间:2024/04/29 17:45
#include <iostream>
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "math.h"
using namespace std;
#define N 50005
int gcd(int a,int b)
{
if(b==0) return a;
else return gcd(b,a%b);
}
int e_gcd( int a, int b,int *x, int *y)//扩展欧几里得
{
if(b==0){
*x=1;
*y=0;
return a;
}
int ans=e_gcd(b,a%b,x,y), temp=*x;
*x=*y;
*y=temp-a/b*(*y);
return ans;
}
int main()
{
int a,b;
while(scanf("%d%d",&a,&b)!=EOF)
{
int x,y;
int ans=e_gcd(a,b,&x,&y);
printf("gcd:%d\n%d %d\n",ans,x,y);
}
}
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "math.h"
using namespace std;
#define N 50005
int gcd(int a,int b)
{
if(b==0) return a;
else return gcd(b,a%b);
}
int e_gcd( int a, int b,int *x, int *y)//扩展欧几里得
{
if(b==0){
*x=1;
*y=0;
return a;
}
int ans=e_gcd(b,a%b,x,y), temp=*x;
*x=*y;
*y=temp-a/b*(*y);
return ans;
}
int main()
{
int a,b;
while(scanf("%d%d",&a,&b)!=EOF)
{
int x,y;
int ans=e_gcd(a,b,&x,&y);
printf("gcd:%d\n%d %d\n",ans,x,y);
}
}
0 0
- 欧几里得模板以及扩展欧几里得
- 欧几里得+扩展欧几里得(转载、模板)
- 欧几里得, 扩展欧几里得算法模板
- 扩展的欧几里得模板
- 扩展欧几里得模板
- 扩展欧几里得 模板
- 【解析】【模板】扩展欧几里得
- 扩展欧几里得模板题
- 扩展欧几里得模板
- 扩展欧几里得模板
- 扩展欧几里得【模板】
- 扩展欧几里得模板
- 扩展欧几里得模板
- 欧几里得gcd+扩展欧几里得exgcd模板
- 欧几里得算法与扩展欧几里得算法模板
- 扩展欧几里得算法(模板)
- 扩展欧几里得原理与模板
- 扩展欧几里得各类问题模板
- Linux的常用部分指令
- SQOOP解决class org.apache.sqoop.Sqoop
- JTAG调试原理
- Android LayerDrawable
- Objective-C 【copy和内存管理】
- 欧几里得模板以及扩展欧几里得
- LeetCode(75) Sort Colors
- 通用makefile
- lib和obj的差别
- 利用pthread_cond_timedwait实现sleep
- hp实训之测试(第四周)
- shell脚本 集成测试多个UiAutomator case类
- AngularJS进阶(六)AngularJS+BootStrap实现弹出对话框
- 关于request.getParameter()与request.setAttribute()的区别