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 11 1 12 5
Output
Infinity
Input
1 0-1 32
Output
-Infinity
Input
0 111 0
Output
0/1
Input
2 22 1 64 5 -7
Output
1/2
Input
1 19 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约分一下,也要注意符号.

 #include<cstdio>
 #include<cstring>
 #include<algorithm>
 using namespace std;
 ],b[];
 int read(){
     ,f=; char ch=getchar();
     '){if (ch=='-') f=-f; ch=getchar();}
     +ch-',ch=getchar();
     return x*f;
 }
 int gcd(int x,int y){
     ?x:gcd(y,x%y);
 }
 int main(){
     n=read(),m=read();
     ; i<=n; i++) a[i]=read();
     ; j<=m; j++) b[j]=read();
     if (n>m){
         ]*b[]>) printf("Infinity"); else
         ]*b[]<) printf("-Infinity");
     }else
     if (n<m){
         printf("0/1");
     }else{
         ],y=b[];
         ) x=-x; ) y=-y;
         int K=gcd(x,y);
         x/=K,y/=K;
         ]*b[]<) printf("-");
         printf("%d/%d",x,y);
     }
     ;
 }

[CodeForces - 197B] B - Limit的更多相关文章

  1. CodeForces 554B(扫房间)

      CodeForces 554B Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u ...

  2. CodeForces 474B(标记用法)

    CodeForces 474B Time Limit:1000MS Memory Limit:262144KB   64bit IO Format:%I64d & %I64u Descript ...

  3. Almost Acyclic Graph CodeForces - 915D (思维+拓扑排序判环)

    Almost Acyclic Graph CodeForces - 915D time limit per test 1 second memory limit per test 256 megaby ...

  4. Persistent Bookcase CodeForces - 707D (dfs 离线处理有根树模型的问题&&Bitset)

    Persistent Bookcase CodeForces - 707D time limit per test 2 seconds memory limit per test 512 megaby ...

  5. 组合——Program B

    CodeForces 478B Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u De ...

  6. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) D. Office Keys time limit per test2 seconds 二分

    D. Office Keys time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  7. codeforces 459E

    codeforces 459E E. Pashmak and Graph time limit per test 1 second memory limit per test 256 megabyte ...

  8. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  9. CodeForces 548D 单调栈

    Mike and Feet Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Subm ...

随机推荐

  1. Entity Framework Core导航属性加载问题

    前言 今天下午在开发的时候发现EF Core实体模型中的导航属性为 null,经排查既不是没有加 virtual 关键字,也不是外键关系映射错误. 解决方法 通过查询官网文档,发现,原因在于EF Co ...

  2. BZOJ 1064: [Noi2008]假面舞会(dfs + 图论好题!)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1064 题意: 思路: 考虑以下几种情况: ①无环并且是树: 无环的话就是树结构了,树结构的话想一下就 ...

  3. [luogu]P1852跳跳棋

    题目重点是每次不能跳过两个棋子 即对于每一个棋子的状态(a,b,c) (a<b<c) 最多有两种移动的方式 1.中间往两边跳 (a,b,c)-->(2b-a,a,c)或(a,c,2b ...

  4. nodejs的dependency.md

    dependency和devDependency的区别 package-a --- package-b (dependency) --- | --- package-c (devDependency) ...

  5. 每日质量NPM包复制_copy-to-clipboard

    一.copy-to-clipboard 官方定义: Simple module exposing copy function 理解: 一个超级简单的复制功能,并且这种方法适用于通过别的事件触发复制功能 ...

  6. _event_phase_team

    EventId 事件ID Phase 阶段ID,从1开始 TeamId 事件玩家分组,攻守(防守为1,进攻为2),自定义阵营(_faction表自定义阵营ID),公会(公会guid) Graveyar ...

  7. 懒懒的Rain的寒假小结

    快开学了,才发现这个寒假算是又废了,放假前满满的雄心壮志要刷多少多少题回家写一会都不行了,唉,在家真不适合学习.可能还是因为没有学习的气氛吧,在家老是就自己一个人,遇到问题或者出现什么错误了没有人可以 ...

  8. leecode第十四题(最长公共前缀)

    class Solution { public: string longestCommonPrefix(vector<string>& strs) { string res=&qu ...

  9. MySQL学习(十二)

    视图 view 在查询中,我们经常把查询结果当成临时表来看, view是什么?view可以看成一张虚拟表,是表通过某种运算得到的一个投影. 表的变化会影响到视图 既然视图只是表的某种查询的投影,所以主 ...

  10. (转)Linux下设置和查看环境变量

    原文地址:<Linux下设置和查看环境变量> Linux的变量种类 按变量的生存周期来划分,Linux变量可分为两类: 1. 永久的:需要修改配置文件,变量永久生效. 2. 临时的:使用e ...