SDUT2015暑假集训14级周赛1 C - 曼联(积分+求最大公yue数)

来源:互联网 发布:淘宝刀剑神域99 编辑:程序博客网 时间:2024/04/30 05:15
C - 曼联
Time Limit:1000MS     Memory Limit:64000KB     64bit IO Format:%lld & %llu
Submit Status Practice ACdream 1204

Description

Suppose there are a polynomial which has n nonzero terms, please print the integration polynomial of the given polynomial.

The polynomial will be given in the following way, and you should print the result in the same way:

k[1] e[1] k[2] e[2] ... k[n] e[n]

where k[i] and e[i] respectively represent the coefficients and exponents of nonzero terms, and satisfies e[1] < e[2] < ... < e[n].

Note:

  • Suppose that the constant term of the integration polynomial is 0.
  • If one coefficient of the integration polynomial is an integer, print it directly.
  • If one coefficient of the integration polynomial is not an integer, please print it by using fraction a/b which satisfies thatis coprime to b.

Input

There are multiple cases.

For each case, the first line contains one integer n, representing the number of nonzero terms.

The second line contains 2*n integers, representing k[1], e[1], k[2], e[2], ..., k[n], e[n]

1 ≤ n ≤ 1000

-1000 ≤ k[i] ≤ 1000, k[i] != 0, 1 ≤ i ≤ n

0 ≤ e[i] ≤ 1000, 1 ≤ i ≤ n

Output

Print the integration polynomial in one line with the same format as the input.

Notice that no extra space is allowed at the end of each line.

Sample Input

31 0 3 2 2 4

Sample Output

1 1 1 3 2/5 5题目大意是给定一个多项式的系数和指数,求解它积分的系数和指数。//注意当系数/指数不为整数时,要用GCD求解最大公yue数(且两数求解最大公寓数应该全为正数)。
#include<iostream>#include<cstring>#include<cstdio>using namespace std;struct node{    int c,e;} q[2015];int G(int a,int b)///{    int t;    if(a<0)        a=-a;    if(b<0)        b=-b;    if(a<b)    {        t=a;        a=b;        b=t;    }    while(b!=0)    {        t=a%b;        a=b;        b=t;    }    return a;}int main(){    int n,m,i,j;    ios::sync_with_stdio(false);    while(cin>>n&&n)    {        for(i=0; i<n; i++)        {            cin>>q[i].c>>q[i].e;        }        for(i=0; i<n; i++)        {            if( q[i].c%(q[i].e+1)==0&&(q[i].e+1)!=0 )            {                printf("%d ", q[i].c/(q[i].e+1)   );            }            else            {                int p=G(q[i].c,q[i].e+1);                printf("%d/%d ",q[i].c/p,(q[i].e+1)/p);            }            if(i==n-1)            {                printf("%d",q[i].e+1);                printf("\n");            }            else                printf("%d ",q[i].e+1);        }    }    return 0;}


0 0
原创粉丝点击