Integration of Polynomial

Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others)

Submit Statistic Next Problem

Problem 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 that a is 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

3

1 0 3 2 2 4

Sample Output

1 1 1 3 2/5 5

Hint

f(x) = 1 + 3x2 + 2x4

After integrating we get: ∫f(x)dx = x + x3 + (2/5)x5

数学的不定积分加GCD

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <list>
#include <algorithm>
#define LL long long
#define RR freopen("output.txt","r",stdoin)
#define WW freopen("input.txt","w",stdout) using namespace std; const int MAX = 100100; const int MOD = 1000000007; int k[1100],e[1100]; int num[1100];
int GCD(int a,int b)
{
return b==0?a:GCD(b,a%b);
}
int main()
{
int n;
while(~scanf("%d",&n))
{
memset(num,0,sizeof(num));
for(int i=0;i<n;i++)
{
scanf("%d %d",&k[i],&e[i]);
e[i]++;
if(k[i]%e[i]==0)
{
k[i]/=e[i];
}
else
{
num[i]=e[i];
int ans=GCD(abs(k[i]),num[i]);
k[i]/=ans;
num[i]/=ans;
}
}
for(int i=0;i<n;i++)
{
if(i)
{
printf(" ");
}
if(num[i])
{
printf("%d/%d %d",k[i],num[i],e[i]);
}
else
{
printf("%d %d",k[i],e[i]);
}
}
printf("\n");
} return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

最新文章

  1. 关于Karaf Container 4.0.7
  2. XML的一些事
  3. js String对象
  4. sql查询某条记录
  5. POJ 1811Prime Test(米勒拉宾素数测试)
  6. [改善Java代码]不要只替换一个类
  7. Ngrok,一款可以帮助你展示网站和联网开发的工具
  8. 实现DIV拖动
  9. Perl 之 use(), require(), do(), %INC and @INC
  10. 解决AJAX在火狐,谷歌都能正常运行,而IE不行的问题
  11. yii2之GridView小部件
  12. 微软黑科技强力注入,.NET C#全面支持人工智能
  13. Logstash利用ruby将有用的日志放到一个ES_INDEX将无用的日志放到另一个ES_INDEX
  14. django中数据库的配置及相关增删改查
  15. tp未验证内容-9
  16. (转) 机器学习很有趣Part6:怎样使用深度学习进行语音识别
  17. c++ shared_ptr的使用
  18. 获取请求地址的IP地址
  19. MySQL中使用连接查询
  20. mfc 虚函数

热门文章

  1. Building a RESTful Web Service Using Spring Boot In Eclipse
  2. C++字符串(String)
  3. MES: ESB
  4. c++的用处
  5. Java中的并发线程操作(只贴代码,内有注释)
  6. 夺命雷公狗ThinkPHP项目之----企业网站6之栏目的添加(主要用模型来验证字段)
  7. 搞不定linux下的无线网卡驱动的权宜之计
  8. nginx for windows中的一项缺陷
  9. [v]Debian类系统的有效国内源
  10. jquery冲突细节