博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 2891
阅读量:5148 次
发布时间:2019-06-13

本文共 2201 字,大约阅读时间需要 7 分钟。

Strange Way to Express Integers
Time Limit: 1000MS   Memory Limit: 131072K
Total Submissions: 19509   Accepted: 6592

Description

Elina is reading a book written by Rujia Liu, which introduces a strange way to express non-negative integers. The way is described as following:

Choose k different positive integers a1, a2, …, ak. For some non-negative m, divide it by every ai (1 ≤ ik) to find the remainder ri. If a1, a2, …, ak are properly chosen, m can be determined, then the pairs (ai, ri) can be used to express m.

“It is easy to calculate the pairs from m, ” said Elina. “But how can I find m from the pairs?”

Since Elina is new to programming, this problem is too difficult for her. Can you help her?

Input

The input contains multiple test cases. Each test cases consists of some lines.

  • Line 1: Contains the integer k.
  • Lines 2 ~ k + 1: Each contains a pair of integers ai, ri (1 ≤ ik).

Output

Output the non-negative integer m on a separate line for each test case. If there are multiple possible values, output the smallest one. If there are no possible values, output -1.

Sample Input

28 711 9

Sample Output

31

Hint

All integers in the input and the output are non-negative and can be represented by 64-bit integral types.

模不互素不能用CRT,所有就有了我解线性方程组的方法?

但是有个关键步骤不太懂。。只是会用这个板子。。

1 #include 
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #define ll long long 9 #define dscan(a) scanf("%d",&a)10 #define mem(a,b) memset(a,b,sizeof a)11 using namespace std;12 #define MAXL 110513 #define Endl endl14 #define maxn 100000515 ll x,y;16 inline ll read()17 {18 ll x=0,f=1;char ch=getchar();19 while(ch<'0'||ch>'9') { if(ch=='-') f=-1;ch=getchar();}20 while(ch>='0'&&ch<='9') {x=10*x+ch-'0';ch=getchar();}21 return x*f;22 }23 ll exgcd(ll a,ll b,ll &x,ll &y){24 if(b==0) {25 x=1;y=0;return a;26 }27 ll d=exgcd(b,a%b,x,y);28 ll temp=x;29 x=y;30 y=temp-a/b*y;31 return d;32 }33 int main()34 {35 ll k,a,b,c,d;36 while(~scanf("%lld",&k))37 {38 cin>>a>>b;39 //cout<<"hhh"<
View Code

 

转载于:https://www.cnblogs.com/TYH-TYH/p/9378510.html

你可能感兴趣的文章
导航,头部,CSS基础
查看>>
[USACO 2017 Feb Gold] Tutorial
查看>>
gzip
查看>>
转负二进制(个人模版)
查看>>
LintCode-Backpack
查看>>
查询数据库锁
查看>>
我对于脚本程序的理解——百度轻应用有感
查看>>
面试时被问到的问题
查看>>
注解小结
查看>>
list control控件的一些操作
查看>>
一月流水账
查看>>
判断字符串在字符串中
查看>>
Linux环境下Redis安装和常见问题的解决
查看>>
HashPump用法
查看>>
cuda基础
查看>>
Vue安装准备工作
查看>>
oracle 创建暂时表
查看>>
201421410014蒋佳奇
查看>>
Xcode5和ObjC新特性
查看>>
LibSVM for Python 使用
查看>>