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 .
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): a0, a1, ..., an - 1, an( - 100 ≤ ai ≤ 100, a0 ≠ 0).
The third line contains m + 1 space-separated integers — the factors of polynomial Q(x): b0, b1, ..., bm - 1, bm( - 100 ≤ bi ≤ 100, b0 ≠ 0).
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.
2 1 1 1 1 2 5
Infinity
1 0 -1 3 2
-Infinity
0 1 1 1 0
0/1
2 2 2 1 6 4 5 -7
1/2
1 1 9 0 -5 2
-9/5
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
取极值。
#include <cstdio>
#include <algorithm>
int main()
{
int x[110],y[110];
int number1,number2;
while(scanf("%d %d",&number1,&number2)!=EOF)
{
for (int Count1=0;Count1<number1+1;Count1++)
{
scanf("%d",&x[Count1]);
}
for (int Count1=0;Count1<number2+1;Count1++)
{
scanf("%d",&y[Count1]);
}
if (number1<number2)
{
printf("0/1\n");
}
else if (number1>number2)
{
if ((x[0]>0&&y[0]>0)||(x[0]<0&&y[0]<0))
{
printf("Infinity\n");
}
else
{
printf("-Infinity\n");
}
}
else if (number1==number2)
{
int flag1=1,flag2=1;
if (x[0]<0)
{
x[0] *=-1;
flag1=0;
}
if (y[0]<0)
{
y[0] *=-1;
flag2=0;
}
int Min;
if (x[0]>y[0])
Min=y[0];
else
Min=x[0];
int p=x[0],q=y[0];
for (int Count1=2;Count1<=Min;Count1++)
{
if (x[0]%Count1==0&&y[0]%Count1==0)
{
p=x[0]/Count1;
q=y[0]/Count1;
}
}
if (flag1==0&&flag2==0||flag1==1&&flag2==1)
printf("%d/%d\n",p,q);
else
{
printf("-%d/%d\n",p,q);
}
}
}
return 0;
}