1635:【例 5】Strange Way to Express Integers
#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的更多相关文章
- 一本通1635【例 5】Strange Way to Express Integers
1635:[例 5]Strange Way to Express Integers sol:貌似就是曹冲养猪的加强版,初看感觉非常没有思路,经过一番艰辛的***,得到以下的结果 随便解释下给以后的自己 ...
- Strange Way to Express Integers
I. Strange Way to Express Integers 题目描述 原题来自:POJ 2891 给定 2n2n2n 个正整数 a1,a2,⋯,ana_1,a_2,\cdots ,a_na ...
- 中国剩余定理+扩展中国剩余定理 讲解+例题(HDU1370 Biorhythms + POJ2891 Strange Way to Express Integers)
0.引子 每一个讲中国剩余定理的人,都会从孙子的一道例题讲起 有物不知其数,三三数之剩二,五五数之剩三,七七数之剩二.问物几何? 1.中国剩余定理 引子里的例题实际上是求一个最小的x满足 关键是,其中 ...
- poj 2891 Strange Way to Express Integers (非互质的中国剩余定理)
Strange Way to Express Integers Time Limit: 1000MS Memory Limit: 131072K Total Submissions: 9472 ...
- POJ2891——Strange Way to Express Integers(模线性方程组)
Strange Way to Express Integers DescriptionElina is reading a book written by Rujia Liu, which intro ...
- [POJ 2891] Strange Way to Express Integers
Strange Way to Express Integers Time Limit: 1000MS Memory Limit: 131072K Total Submissions: 10907 ...
- 数论F - Strange Way to Express Integers(不互素的的中国剩余定理)
F - Strange Way to Express Integers Time Limit:1000MS Memory Limit:131072KB 64bit IO Format: ...
- Strange Way to Express Integers(中国剩余定理+不互质)
Strange Way to Express Integers Time Limit:1000MS Memory Limit:131072KB 64bit IO Format:%I64d & ...
- POJ2891 Strange Way to Express Integers
题意 Language:Default Strange Way to Express Integers Time Limit: 1000MS Memory Limit: 131072K Total S ...
- poj 2981 Strange Way to Express Integers (中国剩余定理不互质)
http://poj.org/problem?id=2891 Strange Way to Express Integers Time Limit: 1000MS Memory Limit: 13 ...
随机推荐
- sqlserver使用EF模型经验
sqlserver使用EF模型经验 EF模型使用本人在之前两三年中从没使用过,所以刚开始使用就会踩上许多的坑.今天我不单单说下自己所踩的一些坑与当前公司中使用EF模型设计的理念,即是为我自己做个笔记, ...
- springboot启动流程(四)application配置文件加载过程
所有文章 https://www.cnblogs.com/lay2017/p/11478237.html 触发监听器加载配置文件 在上一篇文章中,我们看到了Environment对象的创建方法.同时也 ...
- charles 的安装和手机配置 (我用的win7系统 ,和 iphone8 的配置)
2018/12/17 由于想抓一下某个手机上app的数据,然后就装了charles,纯记录一下,便于以后不用再查资料.个人参考的网址:https://blog.csdn.net/weixin_4233 ...
- layer弹出层移动端组件
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name ...
- Vue中遍历数组的新方法
1.foreach foreach循环对不能使用return来停止循环 search(keyword){ var newList = [] this.urls.forEach(item =>{ ...
- Point to class member
#include <iostream> using namespace std; class Student { public: Student(string n, int nu):nam ...
- leetcode-100. Same Tree · Tree + DFS + Queue
题面 对比两棵二叉树是否相同,返回结果. 思路 1. 递归解决DFS 首先判断根节点,如果都空,返回true: 如果一空一不空,返回false: 如果都不空,判断两节点值是否相同,若不同,返回fals ...
- Oracle学习笔记——Linux下开启Oracle
1.开启数据库 sqlplus / as sysdba startup 2.启动监听:lsnrctl start; 查看监听状态:lsnrctl status; 3.登入数据库 Linux 设置 ...
- page页面403
nginx 没有监听内网地址 必须要用域名访问
- Qt 4.8.5 + MinGW32 + Qt creater 安装
Qt 4.8.5 + MinGW32 + Qt creater 安装 下载文件 文件版本 Qt 4.8.5 MinGW 0.4.4 Qt Creator 2.8或2.8.1 gdb-7.4-MinGW ...