POJ1061 青蛙的约会 扩展欧几里得
2016-04-21 11:32
381 查看
模板题,这题有一点需要注意,因为要求非负,ax=b(mod L) 得保证 a>=0
View Code
#include <stdio.h> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <string.h> using namespace std; typedef long long LL; const int INF=0x3f3f3f3f; const int N=5e4+1; LL exgcd(LL a,LL b,LL& x,LL& y){ if(!b){ x=1; y=0; return a; } LL d=exgcd(b,a%b,y,x); y-=a/b*x; return d; } int main(){ LL x,y,m,n,l; scanf("%I64d%I64d%I64d%I64d%I64d",&x,&y,&m,&n,&l); LL a=(m-n),b=y-x; if(a<0)a=-a,b=-b; a%=l,b%=l; LL d=exgcd(a,l,x,y); if(b%d)printf("Impossible\n"); else{ x*=b/d; LL tmp=l/d; x=(x%tmp+tmp)%tmp; printf("%I64d\n",x); } return 0; }
View Code
相关文章推荐
- cgi fastcgi wsgi
- java实现表达式求值
- android studio中批量混淆打包
- CocoaPods介绍与使用
- java关键字Volatile Transient
- Thinkphp,Jquery,Ajax异步发布
- 利用mask layer 勾View
- 关于同一台电脑启2个tomcat问题
- 工业相机编程模型和流程
- GenericServlet的基本
- html基础标签-2-textarea文本域
- 解决vs创建dll编译无法生成lib文件问题
- A Complete Tutorial on Tree Based Modeling from Scratch (in R & Python)
- saltstack(二) master、minion常用配置选项
- ActiveMQ的优点
- ORACLE数据库事务隔离
- 针对物联网中MQTT协议的学习_客户端代码学习笔记(二)
- Scala中TypeTags和Manifests的用法
- Yii CActiveForm 客户端验证(enableClientValidation)和自定义验证
- 聚集索引和非聚集索引的区别有哪些(转)