poj1061 Exgcd
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
#define ll long long int gcd(ll a,ll b)
{
return b==?a:gcd(b,a%b);
} void exgcd(ll a,ll b,ll &x,ll &y)
{
if(b==)
{
x=;
y=;
return;
}
ll x1,y1;
exgcd(b,a%b,x1,y1);
x=y1;
y=x1-(a/b)*y1;
}
int main()
{
ll x,y,m,n,l;
ll t,k,p;
while(cin>>x>>y>>m>>n>>l)
{
p=gcd(n-m,l);
if((x-y)%p)
cout<<"Impossible"<<endl;
else
{
exgcd(n-m,l,t,k);
t=t*(x-y)/p;
t=(t%(l/p)+(l/p))%(l/p);
cout<<t<<endl;
}
}
return ;
}
//d求得的是最大公约数
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
#define ll long long void exgcd(ll a,ll b,ll &d,ll &x,ll &y)
{
if(b==)
{
x=;
y=;
d=a;
return;
}
ll x1,y1;
exgcd(b,a%b,d,x1,y1);
x=y1;
y=x1-(a/b)*y1;
}
int main()
{
ll x,y,m,n,l;
ll t,k,p;
while(cin>>x>>y>>m>>n>>l)
{
exgcd(n-m,l,p,t,k);
if((x-y)%p)
cout<<"Impossible"<<endl;
else
{
t=t*(x-y)/p;
t=(t%l+l)%l;
cout<<t<<endl;
}
}
return ;
}
poj1061 Exgcd的更多相关文章
- pOJ-1061 exgcd求同余方程组
链接 就是求(m-n)*a+b*l=y-x, 类似于求解a*x+b*y=c,r=gcd(a,b),当c%r==0时有解,用exgcd求出a*x+b*y=gcd(a,b)的解,然后x*c/gcd(a,b ...
- exgcd求解同余方程的最小正整数解 poj1061 poj2115
这两题都是求解同余方程,并要求出最小正整数解的 对于给定的Ax=B(mod C) 要求x的最小正整数解 首先这个式子可转化为 Ax+Cy=B,那么先用exgcd求出Ax+Cy=gcd(A,C)的解x ...
- POJ1061 青蛙的约会 exgcd
这个题虽然很简单,但是有一个比较坑的地方,就是gcd不一定是1,有可能是别的数.所以不能return 1,而是return a; 题干: Description 两只青蛙在网上相识了,它们聊得很开心, ...
- 欧几里德&扩展以及求解线性方程学习总结--附上poj1061解题报告
欧几里德算法: 欧几里德就是辗转相除法,调用这个gcd(a,b)这个函数求解a,b的最大公约数 公式: gcd(a,b)=gcd(b,a%b):并且gcd(a,b)=gcd(b,a)=gcd(-a,b ...
- POJ1061 青蛙的约会 —— 扩展gcd
题目链接:https://vjudge.net/problem/POJ-1061 青蛙的约会 Time Limit: 1000MS Memory Limit: 10000K Total Submi ...
- exgcd&&中国剩余定理专题练习
hdu1573求中国剩余定理解的个数 #include <iostream> #include <cstdio> using namespace std; int a[100] ...
- 扩展欧几里得 exGCD
Elementary Number Theory - Extended Euclid Algorithm Time Limit : 1 sec, Memory Limit : 65536 KB Jap ...
- POJ1061青蛙的约会[扩展欧几里得]
青蛙的约会 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 108911 Accepted: 21866 Descript ...
- NOIP2012同余方程[exgcd]
题目描述 求关于 x 的同余方程 ax ≡ 1 (mod b)的最小正整数解. 输入输出格式 输入格式: 输入只有一行,包含两个正整数 a, b,用一个空格隔开 输出格式: 输出只有一行,包含一个正整 ...
随机推荐
- Cuckoo for Hashing_双哈希表
问题 B: Cuckoo for Hashing 时间限制: 1 Sec 内存限制: 64 MB提交: 24 解决: 12[提交][状态][讨论版] 题目描述 An integer hash ta ...
- zsh 通信脚本
server #!/bin/zsh #zsh TCP server script zmodload zsh/net/tcp #listening port ztcp -l #This is a fil ...
- linux下动态链接库解决方案(一)
1.c++无法直接调用用c写的动态链接库,如果调用的话可能需要用到一些交叉编译的知识: 2.在c++写的动态链接库无法被调用成功的反思: 在linux下,通常都是使用g++编译器("g++ ...
- oracle触发器设置uuid变量
create or replace trigger tri_org_department after insert or update on bjlt.sys_org for each row dec ...
- 【leetcode】Max Points on a Line(hard)☆
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. ...
- 【python】类中的super().__init__()
来源:百度知道 python中的super( test, self).__init__()是什么意思? 首先找到test的父类(比如是类A),然后把类test的对象self转换为类A的对象,然后&qu ...
- -[__NSCFNumber length]: unrecognized selector sent to instance 0xb0000000000000e3
网络数据解析出现-[__NSCFNumber length]: unrecognized selector sent to instance 0xb0000000000000e3这样的错误,具体 re ...
- chrome进入控制台时自动进入断点模式的解决方法
简单粗暴,不知道为什么,去掉那个√就好了
- openURL的使用方法:
openURL的使用方法: view plaincopy toclipboardprint? [[UIApplication sharedApplication] openURL:[NS ...
- Xcode常用代码块
Xcode的代码片段(Code Snippets)创建自定义的代码片段,当你重用这些代码片段时,会给你带来很大的方便. 常用的: 1.strong:@property (nonatomic,stron ...