[CodeForces - 197B] B - Limit

B - Limit

You are given two polynomials:

  • P(x) = a0·xn + a1·xn - 1 + ... + an - 1·x + an and
  • Q(x) = b0·xm + b1·xm - 1 + ... + bm - 1·x + bm.

Calculate limit .

Input

The first line contains two space-separated integers n and m (0 ≤ n, m ≤ 100) — degrees of polynomials P(x) and Q(x) correspondingly.

The second line contains n + 1 space-separated integers — the factors of polynomial P(x): a0a1, ..., an - 1an ( - 100 ≤ ai ≤ 100, a0 ≠ 0).

The third line contains m + 1 space-separated integers — the factors of polynomial Q(x): b0b1, ..., bm - 1bm ( - 100 ≤ bi ≤ 100, b0 ≠ 0).

Output

If the limit equals  + ∞, print "Infinity" (without quotes). If the limit equals  - ∞, print "-Infinity" (without the quotes).

If the value of the limit equals zero, print "0/1" (without the quotes).

Otherwise, print an irreducible fraction — the value of limit , in the format "p/q" (without the quotes), where p is the — numerator, q (q > 0) is the denominator of the fraction.

Example

Input
2 1
1 1 1
2 5
Output
Infinity
Input
1 0
-1 3
2
Output
-Infinity
Input
0 1
1
1 0
Output
0/1
Input
2 2
2 1 6
4 5 -7
Output
1/2
Input
1 1
9 0
-5 2
Output
-9/5

Note

Let's consider all samples:

You can learn more about the definition and properties of limits if you follow the link: http://en.wikipedia.org/wiki/Limit_of_a_function

这个题目的意思就是,给你两个关于x的多项式,一个作为分子,一个作为分母,x的取值趋于正无穷,求这个分式的值趋于什么(0,inf,-inf或某个确定的值)

其中最高项系数不为0.

那么,我们发现,由于x趋于无穷大,那么,除了两个最高项,其他就不用考虑了.

如果n>m,则趋于无穷大,至于是正还是负,要看两个系数同号还是异号.

如果n<m,则值趋向与0.

如果n=m,则输出某数的分数形式,还要用gcd约分一下,也要注意符号.

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 int n,m,a[105],b[105];
 6 int read(){
 7     int x=0,f=1; char ch=getchar();
 8     while (ch<'0'||ch>'9'){if (ch=='-') f=-f; ch=getchar();}
 9     while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
10     return x*f;
11 }
12 int gcd(int x,int y){
13     return y==0?x:gcd(y,x%y);
14 }
15 int main(){
16     n=read(),m=read();
17     for (int i=0; i<=n; i++) a[i]=read();
18     for (int j=0; j<=m; j++) b[j]=read();
19     if (n>m){
20         if (a[0]*b[0]>0) printf("Infinity"); else
21         if (a[0]*b[0]<0) printf("-Infinity");
22     }else
23     if (n<m){
24         printf("0/1");
25     }else{
26         int x=a[0],y=b[0];
27         if (x<0) x=-x; if (y<0) y=-y;
28         int K=gcd(x,y);
29         x/=K,y/=K;
30         if (a[0]*b[0]<0) printf("-");
31         printf("%d/%d",x,y);
32     }
33     return 0;
34 }
View Code

 

转载于:https://www.cnblogs.com/whc200305/p/7214365.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值