思路:很裸的求相遇问题。

  1. #include<bits/stdc++.h>
  2. #define LL long long
  3. #define fi first
  4. #define se second
  5. #define mk make_pair
  6. #define pii pair<int, int>
  7.  
  8. using namespace std;
  9.  
  10. const int N = 2e6 + ;
  11. const int M = 1e5 + ;
  12. const int inf = 0x3f3f3f3f;
  13. const LL INF = 0x3f3f3f3f3f3f3f3f;
  14. const int mod = 1e9 +;
  15.  
  16. LL a, b, c, m, n, L, x, y;
  17.  
  18. LL exgcd(LL a, LL b, LL &x, LL &y) {
  19. if(!b) {
  20. x = ; y = ;
  21. return a;
  22. } else {
  23. LL gcd, t; gcd = exgcd(b, a % b, x, y);
  24. t = x; x = y; y = t - (a / b) * y;
  25. return gcd;
  26. }
  27. }
  28.  
  29. int main() {
  30. scanf("%lld%lld%lld%lld%lld", &a, &b, &m, &n, &L);
  31. LL gcd = exgcd(n - m, L, x, y);
  32. if((a - b) % gcd != ) {
  33. puts("Impossible");
  34. } else {
  35. x *= ((a - b) / gcd);
  36. x %= L / gcd;
  37. if(x < ) x += abs(L / gcd);
  38. printf("%lld\n", x);
  39. }
  40. return ;
  41. }
  42.  
  43. /*
  44. */

bzoj 1477 扩展欧几里德的更多相关文章

  1. bzoj 1407 扩展欧几里德

    思路:枚举洞穴个数,用扩展欧几里德暴力判断没两个人的周期. #include<bits/stdc++.h> #define LL long long #define fi first #d ...

  2. BZOJ 1477: 青蛙的约会

    二次联通门 : BZOJ 1477: 青蛙的约会 /* BZOJ 1477: 青蛙的约会 扩展欧几里得 列出方程, 判断一下 */ #include <iostream> #include ...

  3. (扩展欧几里德算法)zzuoj 10402: C.机器人

    10402: C.机器人 Description Dr. Kong 设计的机器人卡尔非常活泼,既能原地蹦,又能跳远.由于受软硬件设计所限,机器人卡尔只能定点跳远.若机器人站在(X,Y)位置,它可以原地 ...

  4. [BZOJ1407][NOI2002]Savage(扩展欧几里德)

    题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1407 分析: m,n范围都不大,所以可以考虑枚举 先枚举m,然后判定某个m行不行 某个 ...

  5. 欧几里德与扩展欧几里德算法 Extended Euclidean algorithm

    欧几里德算法 欧几里德算法又称辗转相除法,用于计算两个整数a,b的最大公约数. 基本算法:设a=qb+r,其中a,b,q,r都是整数,则gcd(a,b)=gcd(b,r),即gcd(a,b)=gcd( ...

  6. 51nod 1352 扩展欧几里德

    给出N个固定集合{1,N},{2,N-1},{3,N-2},...,{N-1,2},{N,1}.求出有多少个集合满足:第一个元素是A的倍数且第二个元素是B的倍数. 提示: 对于第二组测试数据,集合分别 ...

  7. CF 7C. Line(扩展欧几里德)

    题目链接 AC了.经典问题,a*x+b*y+c = 0整数点,有些忘记了扩展欧几里德,复习一下. #include <cstdio> #include <iostream> # ...

  8. poj2142-The Balance(扩展欧几里德算法)

    一,题意: 有两个类型的砝码,质量分别为a,b;现在要求称出质量为d的物品, 要用多少a砝码(x)和多少b砝码(y),使得(x+y)最小.(注意:砝码位置有左右之分). 二,思路: 1,砝码有左右位置 ...

  9. poj2115-C Looooops(扩展欧几里德算法)

    本题和poj1061青蛙问题同属一类,都运用到扩展欧几里德算法,可以参考poj1061,解题思路步骤基本都一样.一,题意: 对于for(i=A ; i!=B ;i+=C)循环语句,问在k位存储系统中循 ...

随机推荐

  1. 目标世界上最小的Linux系统—ttylinux体验

    ttylinux的官方网址:http://ttylinux.net/ 简单翻译一下: 你当前访问的是ttylinux的主页,一个针对多种CPU架构的极小的GNU/Linux系统.最小的ttylinux ...

  2. Android 解决adb server is out of date. killing... ADB server didn't ACK * failed to star

    The connection to adb is down, and a severe error has occured. [-- :: - HelloOPone] You must restart ...

  3. lvs学习总结

    看的马哥的视频 NAT1.Director的DIP地址与集群节点必须在同一个网络中[vlan或者subnat] .RIP地址通常是私有地址,仅用于和DIP进行通信 .Director处理进出的所有通信 ...

  4. 动态切换input的 disables 属性

    $("input[type='text']").each(function(){ if($(this).data('parent_id')){ var _each_this_par ...

  5. Tomcat报错java.lang.ClassNotFoundException: 2localhost.org.apache.juli.FileHandler

    Can't load log handler "1catalina.org.apache.juli.FileHandler" java.lang.ClassNotFoundExce ...

  6. Jmeter 重要测试指标释义

    Aggregate Report 是 JMeter 常用的一个 Listener,中文被翻译为“聚合报告”.今天再次有同行问到这个报告中的各项数据表示什么意思,顺便在这里公布一下,以备大家查阅. 如果 ...

  7. onCreateView的一个细节--Fragment

    public View onCreateView(LayoutInflater inflater, ViewGroup contaiiner, Bundle savedInstanceState) 在 ...

  8. HDU 1002 A + B Problem II (大数加法)

    题目链接 Problem Description I have a very simple problem for you. Given two integers A and B, your job ...

  9. Spring 路由地址的基本使用

    1.下面是spring的使用基本框架连接 https://www.cnblogs.com/HD/p/4103239.html

  10. MSSQL数据库 事务隔离级别

    数据库事务的隔离级别有4个,由低到高依次为Read uncommitted .Read committed .Repeatable read .Serializable ,这四个级别可以逐个解 脏读 ...