总时间限制: 
5000ms

内存限制: 
65536kB
描述
Your rich uncle died recently, and the heritage needs to be divided among your relatives and the church (your uncle insisted in his will that the church must get something). There are N relatives (N <= 18) that were mentioned in the will. They are sorted in descending order according to their importance (the first one is the most important). Since you are the computer scientist in the family, your relatives asked you to help them. They need help, because there are some blanks in the will left to be filled. Here is how the will looks:

Relative #1 will get 1 / ... of the whole heritage, 
Relative #2 will get 1 / ... of the whole heritage,
---------------------- ...
Relative #n will get 1 / ... of the whole heritage.

The logical desire of the relatives is to fill the blanks in such way that the uncle's will is preserved (i.e the fractions are non-ascending and the church gets something) and the amount of heritage left for the church is minimized.

输入
The only line of input contains the single integer N (1 <= N <= 18).
输出
Output the numbers that the blanks need to be filled (on separate lines), so that the heritage left for the church is minimized.
样例输入
2
样例输出
2
3
来源
ural 1108
贪心的来想如果只有一个人那就是1/2 , 两个个人就是1/2,1/3 ,还剩下1/6,如果还要分给下一个人,就会1/7 ,还剩1/42,同理下一个人得1/43,然后看出规律了吧,
然后我们就涉及到了高精乘,然而普通高精乘是过不了的,所以可以用fft,或者ntt这种黑科技(奇技淫巧)。
以下是我ntt
 #include <iostream>
#include <cstring>
#include <cstdio>
using namespace std ;
typedef long long LL ;
const int P = ( << ) + , N = << , G = , NUM = ;
int m , len , l1 , l2 ;
LL a[N] , b[N] , wn[NUM] ; void Init( )
{
scanf( "%d" , &m ) ;
if( m > ) l1 = , l2 = , a[] = , b[] = , len = ;
} LL quick_mod( LL a , LL b , LL m )
{
LL ans = 1ll ;
a %= m ;
while( b )
{
if( b & ) ans = ans * a % m ;
b >>= ;
a = a * a % m ;
}
return ans ;
} void Rader( LL a[] , int n )
{
int j = n >> ;
for( int i = ; i < n - ; ++i )
{
if( i < j ) swap( a[i] , a[j] ) ;
int k = n >> ;
while( j >=k )
{
j -= k ;
k >>= ;
}
if( j < k ) j += k ;
} } void NTT( LL a[] , int n , int on )
{
Rader( a , n ) ;
int id = ;
for( int h = ; h <= n ; h <<= )
{
++id ;
for( int j = ; j < n ; j += h )
{
LL w = ;
for( int k = j ; k < j + ( h >> ) ; ++k )
{
LL u = a[k] % P ;
LL t = w * a[k+(h>>)] % P ;
a[k] = ( u + t ) % P ;
a[k+(h>>)] = ( u - t + P ) % P ;
w = w * wn[id] % P ;
}
}
}
if( on == - )
{
for( int i = ; i < ( n >> ) ; ++i ) swap( a[i] , a[n-i] ) ;
LL inv = quick_mod( n , P - , P ) ;
for( int i = ; i < n ; ++i ) a[i] = a[i] * inv % P ;
} } void Conv( LL a[] , LL b[] , int n )
{
NTT( a , n , ) ;
NTT( b , n , ) ;
for( int i = ; i < n ; ++i )
a[i] = a[i] * b[i] % P ;
NTT( a , n , - ) ;
} void Transfer( LL a[] , int n )
{
for( int i = ; i < n ; ++i )
{
a[i+] += a[i]/ ;
a[i] %= ;
if( a[i] ) l1 = i ;
} ++l1 ;
} void Update( LL b[] , int n )
{
int t = ; l2 = n ;
for( int i = ; i <= n ; ++i )
{
b[i] = a[i] + t ;
t = b[i]/ ; b[i] %= ;
}
if( b[l1] ) ++l2 ; } void print( LL b[] , int n )
{
for( int i = l2 - ; i >= ; --i ) putchar( b[i] + '' ) ;
puts( "" ) ;
} void Length( int l1 , int l2 )
{
while( len <= (l1<<) || len <= (l2<<) ) len <<= ;
} void Getwn( )
{
for( int i = ; i < NUM ; ++i ) wn[i] = quick_mod( G , (P-)/(<<i) , P ) ;
} void Solve( )
{
if( m >= ) puts( "" ) ;
if( m >= ) puts( "" ) ;
if( m <= ) return ;
Getwn( ) ;
for( int i = ; i <= m ; ++i )
{
for( int i = l2 ; i <= len ; ++i ) b[i] = ;
Conv( a , b , len ) ;
Transfer( a , len ) ;
Update( b , l1 ) ;
print( b , l2 ) ;
Length( l1 , l2 ) ;
} } int main( )
{
Init( ) ;
Solve( ) ;
return ;
}

NOIopenjudge 407:Heritage的更多相关文章

  1. R自动数据收集第一章概述——《List of World Heritage in Danger》

      导包     library(stringr) library(XML) library(maps) heritage_parsed <- htmlParse("http://en ...

  2. Atitit jsr规范有多少个  407个。Jsr规范大全

    Atitit jsr规范有多少个  407个.Jsr规范大全 1.1. JCP维护职能是发展和更新.1 1.2. Java技术规范.参考实现(RI).技术兼容包(TCK)1 1.3. JCP维护的规范 ...

  3. 洛谷P1827 美国血统 American Heritage

    P1827 美国血统 American Heritage 54通过 90提交 题目提供者JOHNKRAM 标签USACO 难度普及- 提交  讨论  题解 最新讨论 暂时没有讨论 题目描述 农夫约翰非 ...

  4. USACO3.42American Heritage(二叉树)

    已知中前 求后序 递归一下 有一些小细节 /* ID: shangca2 LANG: C++ TASK: heritage */ #include <iostream> #include& ...

  5. USACO 3.4 American Heritage

    American Heritage Farmer John takes the heritage of his cows very seriously. He is not, however, a t ...

  6. HTTP请求错误400、401、402、403、404、405、406、407、412、414、500、501、502解析

    HTTP 错误 400 400 请求出错 由于语法格式有误,服务器无法理解此请求.不作修改,客户程序就无法重复此请求. HTTP 错误 401 401.1 未授权:登录失败 此错误表明传输给服务器的证 ...

  7. Spring Cloud项目中通过Feign进行内部服务调用发生401\407错误无返回信息的问题

    问题描述 最近在使用Spring Cloud改造现有服务的工作中,在内部服务的调用方式上选择了Feign组件,由于服务与服务之间有权限控制,发现通过Feign来进行调用时如果发生了401.407错误时 ...

  8. LintCode 407: Plus One

    LintCode 407: Plus One 题目描述 给定一个非负数,表示一个数字数组,在该数的基础上+1,返回一个新的数组. 该数字按照位权大小进行排列,位权最大的数在列表的最前面. 样例 给定 ...

  9. (第六场)Heritage of skywalkert 【玄学】

    题目链接:https://www.nowcoder.com/acm/contest/144/J 标题:J.Heritage of skywalkert | 时间限制:1 秒 | 内存限制:256M s ...

随机推荐

  1. asp.net(c#)有关 Session 操作的几个误区

    1. this.Session["username"] = null  HttpSessionState 内部使 用 NameObjectCollection 类型的集合对象来存储 ...

  2. UAC新解(有非正常手段可以绕过)

    360第一次注册是需要弹,可是以后就不弹了开机自启动不弹框,开机自启动不弹框 服务是system权限再说一句,一般程序也不需要过UAC系统启动项白名单.UAC有一个白名单机制.还有UAC也可以通过wu ...

  3. Android 用Intent和Bundle传递参数

    传递方: //点击btn_sub传递 fieldHeight.getText()和 fieldWeight.getText() private void setListeners()    {    ...

  4. Redisson使用起来很方便,但是需要redis环境支持eval命令

    Redisson使用起来很方便,但是需要redis环境支持eval命令,否则一切都是悲剧,比如me.结果还是要用RedisCommands去写一套.例子就如下,获得一个RLock锁对象,然后tryLo ...

  5. linux移植简介[MS2]

    一:修改Makefile 1添加编译选项,2添加时钟 二:图形化配置(make menuconfig) 此时生成zlmage,  可以跑起来 三:对NandFlash配置,yaffs2 文件系统配置, ...

  6. Nginx+Keepalived 做负载均衡器

    1.安装 keepalived   1 2 3 4 5 6 7 8 9 tar zxvf keepalived-XXXX.tar.gz ./configure --prefix=/usr/local/ ...

  7. 利用逻辑运算符?"三个数字比大小

    static void Main(string[] args)        {            int a, b, c;            while (true)            ...

  8. c程序设计语言_习题8-4_重新实现c语言的库函数fseek(FILE*fp,longoffset,intorigin)

      fseek库函数 #include <stdio.h> int fseek(FILE *stream, long int offset, int origin); 返回:成功为0,出错 ...

  9. ASP.NET MVC 3.0 Controller基础

    ASP.NET MVC 3.0 Controller基础   1.Controller类与方法 Controller(控制器)是ASP.NET MVC的核心,负责处理浏览器请求,并作出响应.Cotro ...

  10. Android命名规范(自定义)

    此规范参考自android源码,并加以改进,仅供个人使用,如果你觉得还有可取之处,可以参考下,以后有好的规则,再补充 总体规范: 类名要清晰,能反映出这个类的作用,最好能达到见名知义的效果 方法名要使 ...