#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,m,a,lcm,now;
bool flag;
void exgcd(ll a,ll b,ll &d,ll &x,ll &y)
{
if(b==)
{
d=a;
x=;
y=;
}
else
{
exgcd(b,a%b,d,x,y);
ll t=x;
x=y;
y=t-a/b*y;
}
}
int main()
{
ll d,x,y,k;
while(~scanf("%lld",&n))
{
scanf("%lld%lld",&m,&a);
lcm=m;now=a;flag=true;
for(int i=;i<n;i++)
{
scanf("%lld%lld",&m,&a);
a=((a%m)-(now%m)+m)%m;
exgcd(lcm,m,d,x,y);
if(a%d==)
k=(x*(a/d)%(m/d)+(m/d))%(m/d);
else flag=false;
now+=k*lcm;
lcm=lcm*m/d;
now=((now%lcm)+lcm)%lcm;
}
if(!flag) printf("-1");
else printf("%lld",now);
puts("");
}
return ;
}

1635:【例 5】Strange Way to Express Integers的更多相关文章

  1. 一本通1635【例 5】Strange Way to Express Integers

    1635:[例 5]Strange Way to Express Integers sol:貌似就是曹冲养猪的加强版,初看感觉非常没有思路,经过一番艰辛的***,得到以下的结果 随便解释下给以后的自己 ...

  2. Strange Way to Express Integers

    I. Strange Way to Express Integers 题目描述 原题来自:POJ 2891 给定 2n2n2n 个正整数 a1,a2,⋯,ana_1,a_2,\cdots ,a_na​ ...

  3. 中国剩余定理+扩展中国剩余定理 讲解+例题(HDU1370 Biorhythms + POJ2891 Strange Way to Express Integers)

    0.引子 每一个讲中国剩余定理的人,都会从孙子的一道例题讲起 有物不知其数,三三数之剩二,五五数之剩三,七七数之剩二.问物几何? 1.中国剩余定理 引子里的例题实际上是求一个最小的x满足 关键是,其中 ...

  4. poj 2891 Strange Way to Express Integers (非互质的中国剩余定理)

    Strange Way to Express Integers Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 9472   ...

  5. POJ2891——Strange Way to Express Integers(模线性方程组)

    Strange Way to Express Integers DescriptionElina is reading a book written by Rujia Liu, which intro ...

  6. [POJ 2891] Strange Way to Express Integers

    Strange Way to Express Integers Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 10907 ...

  7. 数论F - Strange Way to Express Integers(不互素的的中国剩余定理)

    F - Strange Way to Express Integers Time Limit:1000MS     Memory Limit:131072KB     64bit IO Format: ...

  8. Strange Way to Express Integers(中国剩余定理+不互质)

    Strange Way to Express Integers Time Limit:1000MS Memory Limit:131072KB 64bit IO Format:%I64d & ...

  9. POJ2891 Strange Way to Express Integers

    题意 Language:Default Strange Way to Express Integers Time Limit: 1000MS Memory Limit: 131072K Total S ...

  10. poj 2981 Strange Way to Express Integers (中国剩余定理不互质)

    http://poj.org/problem?id=2891 Strange Way to Express Integers Time Limit: 1000MS   Memory Limit: 13 ...

随机推荐

  1. (十四)Activitivi5之个人任务分配

    一.个人任务分配 1.1 方式一:直接流程图配置中写死: 1.2 方式二:使用流程变量 我们在启动流程的时候设置流程变量即可 /** * 启动流程实例 */ @Test public void sta ...

  2. (三)springmvc之注解的基本使用

    一.@Controller @Controller 标记一个类是Controller 二.RequestMapping  地址映射 2.1 Value的操作. 注解在类上面    (父)       ...

  3. 微软发布云端基因服务:推动AI驱动的精准医疗

    微软发布云端基因服务:推动AI驱动的精准医疗 2018年03月07日 00:00:00 微软研究院AI头条 阅读数:117    版权声明:本文为博主原创文章,未经博主允许不得转载. https:// ...

  4. 表空间 oracle

    --create table create table table_name ( column1 varchar2(20) not null, column2 number(8) not null, ...

  5. 可视化利器 TensorBoard

    人工智能的黑盒: TensorBoard 的作用: 1.用TensorFlow保存图的信息到日志中 tfsummary.FileWriter("日志保存路径", sess.grap ...

  6. fastclick插件中存在的bug

    1.在vue项目中安装fastclick插件 npm install --save fastclick 2.在main.js中引入并绑定到body import FastClick from 'fas ...

  7. 【推荐】 Neutralizer 安卓上特殊的均衡器

    首先 直切正题 这个均衡器特殊就特殊在   会产生  特定频率的声音   根据声音来调整  自己喜欢的声音 下载地址: https://d-02.apkplz.org/dl.php?s=czlDeEt ...

  8. 工作流引擎Activiti

    背景: 在计算机尚未普及时,许多工作流程采用手工传递纸张表单的方式,一级一级审批签字, 工作效率非常低下,对于数据统计以及生成报表的功能,需要经过大量的手工操作才能实现. 随着电脑的普及,这些工作的参 ...

  9. redis数据结构分析 (redisObject、SDS)

    redis是一个key-value储存系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合).zset(sorted set ...

  10. X宝个人支付到账

    扫码登录,能看懂的我就不多说了,封了我多少篇文章了!!!!X宝个人到账通知.