题解:

要求s+px=t+qx (mod L)

移项 (p-q)x=t-s (mod L)

等价于 (p-q)x+Ly=t-s

即ax+by=c的方程最小非负根

exGcd后乘个C

 #include<cstdio>
typedef long long ll;
using namespace std;
ll s,t,p,q,L;
ll gcd (ll x,ll y)
{
return y==?x:gcd(y,x%y);
}
ll exGcd(ll a,ll b,ll &x,ll &y)
{
if (b==) return x=,y=,a;
ll r=exGcd(b,a%b,y,x);
y-=(a/b)*x;
return r;
}
int main()
{
scanf("%lld%lld%lld%lld%lld",&s,&t,&p,&q,&L);
ll a=(p-q+L)%L,b=L,c=(t-s+L)%L,x,y,G=gcd(a,b);
if (c%G!=)
{
puts("Impossible");
return ;
}
a/=G,b/=G,c/=G;
exGcd(a,b,x,y);
x=(x%b+b)%b;
x=x*c%b;
printf("%lld\n",x);
return ;
}

最新文章

  1. PHP+MYSQL网站SQL Injection攻防
  2. myBatis之事务管理
  3. Spring相关:jdom学习:读取xml文件
  4. 【python】2048
  5. Add Customerlize Button in More Button List In Odoo
  6. 树莓派上搭建基于Python+web.py+fastcgi+lighttpd的网站
  7. VC实用小知识总结 (一),转http://blog.csdn.net/myiszjf/article/details/10007431
  8. Oracle EBS-SQL (BOM-5):检查有BOM但物料状态为NEW的物料.sql
  9. Clock Pictures
  10. poj 3128 Leonardo&#39;s Notebook (置换群的整幂运算)
  11. JS(总结)
  12. Python之高级特性
  13. HBase原理和设计
  14. oracle中order by造成分页错误
  15. Non-negative Matrix Factorization 非负矩阵分解
  16. Unsafe 学习和源码阅读
  17. day_11 py 名片管理系统
  18. redis 知识点
  19. vue, vux调用微信点击图片,上传图片,删除图片,接口,其中选图接口,苹果手机显示有问题,查看不到图片,提交会提示fail not exist,解决如下
  20. SQL Tuning Advisor

热门文章

  1. 使用inotify-tools与rsync构建实时备份系统
  2. 使用windows api安装windows服务程序(C#)
  3. thinkphp3.2 where 条件查询 复查的查询语句
  4. python+scrapy环境搭建步骤描述
  5. B1008 数组元素循环右移问题 (20分)
  6. AD15添加导入组件
  7. 7 Vue.js实现loading1
  8. Retrofit get post query filed FiledMap
  9. mybatis异常:There is no getter for property named &#39;xxx&#39; in &#39;xxx&#39;
  10. iOS Crash 分析 符号化崩溃日志