题目链接:http://poj.org/problem?id=1707

题意:给出n

在M为正整数且尽量小的前提下,使得n的系数均为整数。

思路:

i64 Gcd(i64 x,i64 y)
{
    if(y==0) return x;
    return Gcd(y,x%y);
}

i64 Lcm(i64 x,i64 y)
{
    x=x/Gcd(x,y)*y;
    if(x<0) x=-x;
    return x;
}

struct fraction
{
    i64 a,b;

    fraction() {}
    fraction(i64 x)
    {
        a=x; b=1;
    }

    fraction(i64 x,i64 y)
    {
        a=x; b=y;
        deal();
    }

    void deal()
    {
        if(b<0) b=-b,a=-a;
        i64 k=Gcd(a,b);
        if(k<0) k=-k;
        a/=k; b/=k;
    }

    fraction operator+(fraction p)
    {
        fraction ans;
        ans.b=Lcm(b,p.b);
        ans.a=ans.b/b*a+ans.b/p.b*p.a;
        ans.deal();
        return ans;
    }

    fraction operator-(fraction p)
    {
        fraction ans;
        ans.b=Lcm(b,p.b);
        ans.a=ans.b/b*a-ans.b/p.b*p.a;
        ans.deal();
        return ans;
    }

    fraction operator*(fraction p)
    {
        fraction ans;
        ans.a=a*p.a;
        ans.b=b*p.b;
        ans.deal();
        return ans;
    }

    fraction operator/(fraction p)
    {
        fraction ans;
        ans.a=a*p.b;
        ans.b=b*p.a;
        ans.deal();
        return ans;
    }

    void print()
    {
        printf("%lld/%lld\n",a,b);
    }
};

fraction B[20];
i64 C[N][N];

void init()
{
    int i,j;
    for(i=1;i<N;i++)
    {
        C[i][0]=C[i][i]=1;
        for(j=1;j<i;j++) C[i][j]=C[i-1][j-1]+C[i-1][j];
    }
    B[0]=fraction(1);
    for(i=1;i<=20;i++)
    {
        B[i]=fraction(0);
        for(j=0;j<i;j++) B[i]=B[i]-fraction(C[i+1][j])*B[j];
        B[i]=B[i]/fraction(C[i+1][i]);
    }
}

int n;
fraction a[N];

int main()
{
    init();
    Rush(n)
    {
        i64 i,L=1;
        for(i=0;i<=n;i++)
        {
            a[i]=fraction(C[n+1][i])*B[i]*fraction(1,n+1);
            L=Lcm(L,a[i].b);
        }
        printf("%lld ",L);
        a[1]=a[1]+fraction(1);
        for(i=0;i<=n;i++) printf("%lld ",L/a[i].b*a[i].a);
        puts("0");
    }
}

  

POJ 1707 Sum of powers(伯努利数)的更多相关文章

  1. [伯努利数] poj 1707 Sum of powers

    题目链接: http://poj.org/problem?id=1707 Language: Default Sum of powers Time Limit: 1000MS   Memory Lim ...

  2. UVa 766 Sum of powers (伯努利数)

    题意: 求 ,要求M尽量小. 析:这其实就是一个伯努利数,伯努利数公式如下: 伯努利数满足条件B0 = 1,并且 也有 几乎就是本题,然后只要把 n 换成 n-1,然后后面就一样了,然后最后再加上一个 ...

  3. ACM:POJ 2739 Sum of Consecutive Prime Numbers-素数打表-尺取法

    POJ 2739 Sum of Consecutive Prime Numbers Time Limit:1000MS     Memory Limit:65536KB     64bit IO Fo ...

  4. [CSAcademy]Sum of Powers

    [CSAcademy]Sum of Powers 题目大意: 给定\(n,m,k(n,m,k\le4096)\).一个无序可重集\(A\)为合法的,当且仅当\(|A|=m\)且\(\sum A_i=n ...

  5. POJ.2739 Sum of Consecutive Prime Numbers(水)

    POJ.2739 Sum of Consecutive Prime Numbers(水) 代码总览 #include <cstdio> #include <cstring> # ...

  6. POJ 2739 Sum of Consecutive Prime Numbers(素数)

    POJ 2739 Sum of Consecutive Prime Numbers(素数) http://poj.org/problem? id=2739 题意: 给你一个10000以内的自然数X.然 ...

  7. Euler's Sum of Powers Conjecture

    转帖:Euler's Sum of Powers Conjecture 存不存在四个大于1的整数的五次幂恰好是另一个整数的五次幂? 暴搜:O(n^4) 用dictionary:O(n^3) impor ...

  8. 【POJ1707】【伯努利数】Sum of powers

    Description A young schoolboy would like to calculate the sum for some fixed natural k and different ...

  9. UVA766 Sum of powers(1到n的自然数幂和 伯努利数)

    自然数幂和: (1) 伯努利数的递推式: B0 = 1 (要满足(1)式,求出Bn后将B1改为1 /2) 参考:https://en.wikipedia.org/wiki/Bernoulli_numb ...

随机推荐

  1. MAC 平台 QT编写iphone程序,加载iphone模拟器失败解决办法

    本日这么多年一直做C++开发,最近要做QT项目,被QT做界面的新特性所吸引.QSS QML的确是亮点. 还有一个就是跨平台这方面,自己玩了玩. 用的QT 的开发包是在官网上下载 qt-opensour ...

  2. Nginx开启gzip压缩功能

    在Nginx安装完成之后,我们可以开启Gzip压缩功能,这里Nginx默认只能对text/html类型的文件进行压缩.下面的指令为开启Gzip的指令: gzip on; gzip_http_versi ...

  3. C# 清楚Cookies

    //销毁Cookies中的数据 if (Request.Cookies["Ticket"] != null) { HttpCookie mycookie; mycookie = R ...

  4. POJ 3164 Command Network 最小树形图

    题目链接: 题目 Command Network Time Limit: 1000MS Memory Limit: 131072K 问题描述 After a long lasting war on w ...

  5. VIM Taglist安装配置和使用

    问题描述:            VIM  Taglist安装于配置 问题解决:             (1)安装Taglist包      (2)解压taglist压缩包         (3)将 ...

  6. 【POJ】【2068】Nim

    博弈论/DP 这是Nim?这不是巴什博奕的变形吗…… 我也不会捉啊,不过一看最多只有20个人,每人最多拿16个石子,总共只有8196-1个石子,范围好像挺小的,嗯目测暴力可做. so,记忆化搜索直接水 ...

  7. [spring]启动时报错:NoSuchMethodError: javax.servlet.http.HttpServletResponse.getStatus()I

    Spring V4.1以后的版本在不支持Servlet3.0的应用服务器上跑时会报如下错误: NoSuchMethodError: javax.servlet.http.HttpServletResp ...

  8. Unsupervised Learning: Use Cases

    Unsupervised Learning: Use Cases Contents Visualization K-Means Clustering Transfer Learning K-Neare ...

  9. NData BUG 记录

    一.collection 如果设计如下页面 页面模型如下 using UnityEngine; using System.Collections; using System.Collections.G ...

  10. java 中 String 类的几个问题

    首先,我们要搞清楚,在java中,引用和基本数据类型是存储在栈中的.而对象是存储在堆中的. 只有一个例外,就是String对象. 例如: String str1="test"; S ...