excrt板子题

 #include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define ll long long
#define N 100010
#define rint register int
#define ll long long
#define il inline
using namespace std;
//re
int n;
ll A[N],B[N];
ll qadd(ll x,ll y,const ll &mo){ll ans=;while(y){if(y&)ans=(ans+x)%mo;x=(x+x)%mo;y>>=;}return ans;}
ll qpow(ll x,ll y,const ll &mo){ll ans=;while(y){if(y&)ans=(ans*x)%mo;x=(x*x)%mo;y>>=;}return ans;}
ll exgcd(ll a,ll b,ll &x,ll &y){
if(b==){x=,y=;return a;}
ll ans=exgcd(b,a%b,x,y);
ll t=x;x=y;y=t-a/b*y;
return ans;
}
ll excrt()
{
ll x,y,ans=A[],M=B[],bg;
for(int i=;i<=n;i++)
{
ll a=M,b=B[i],c=(A[i]-ans%b+b)%b;
ll gcd=exgcd(M,b,x,y);bg=b/gcd;
if(c%gcd!=) return -;
x=qadd(x,c/gcd,bg);
ans+=x*M;
M*=bg;
ans=(ans%M+M)%M;
}
return ans;
} int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%lld%lld",&B[i],&A[i]);
printf("%lld\n",excrt());
return ;
}

最新文章

  1. 优化MySchool数据库设计之【巅峰对决】
  2. iOS 实用博客整理(连载版)
  3. Delphi 用文件流读取文本文件字符串的方法
  4. 电脑无法登陆ftp
  5. Eclipse Gtk+
  6. 用setTimeout 代替 setInterval实时拉取数据
  7. Xcode-Xcode 7.3 解决不能自动联想问题-备
  8. C# Linq Group By 多个字段并返回给实体类List
  9. eclipse配置自动提示EXTJS和jQurey
  10. ural1037 Memory Management
  11. 洛谷P3459 [POI2007]MEG-Megalopolis(树链剖分,Splay)
  12. 章节十、3-CSS Selector---用CSS Selector - ID定位元素
  13. 原生JS插件(超详细)
  14. Springboot添加定时任务
  15. jquery遇到的问题
  16. AutoMapper自动映射
  17. Transcranial magnetic stimulation (TMS)
  18. jitter
  19. .net core2 mvc项目中,加入RazorPages页面
  20. OSGi 系列(七)之服务的监听、跟踪、声明等

热门文章

  1. Codevs 1077 多源最短路( Floyd水 )
  2. 【转】H5 input search 提交事件
  3. nginx的一些
  4. Problem 13
  5. 配置监听器 服务器启动时 检索常用数据 保存在application中 减少数据的查询操作(OA项目)
  6. Linux Kernel(Android) 加密算法总结(一)(cipher、compress、digest)
  7. Android 进程常驻(5)----开机广播的简单守护以及总结
  8. 第一篇、Android Supersu 权限管理定制,隐藏过滤权限,指定APP最高权限
  9. 利用js在文本框末尾获得焦点
  10. ContextMenu的使用具体解释