FZU 1084 Three powers
来源:互联网 发布:自考与网络教育的区别 编辑:程序博客网 时间:2024/06/15 12:37
Three powers
Time Limit:1sMemory limit:32MAccepted Submit:96Total Submit:217
Consider the set of all non-negative integer powers of 3.
S = { 1, 3, 9, 27, 81, ... }
Consider the sequence of all subsets of S ordered by the value of the sum of their elements. The question is simple: find the set at the n-th position in the sequence and print it in increasing order of its elements.
Input
Each line of input contains a number n, which is a positive integer with no more than 19 digits. The last line of input contains 0 and it should not be processed.Output
For each line of input, output a single line displaying the n-th set as described above, in the format used in the sample output.Sample input
171478311259009816340490
Output for sample input
{ }{ 3, 9 }{ 1, 9, 27 }{ 3, 9, 27, 6561, 19683 }{ 59049, 3486784401, 205891132094649, 717897987691852588770249 }
Original: Waterloo
解题:
题目的意思是,3的次幂所组成的集合S,按从小到大排列组合成一些数,最小的为空,比如:{},{1},{3},{1,3},{9}···刚开始还是没发现规律,查了下资料发现二进制关系。如前几项组合成的数为0,1,3,4,9,10,12····相对应的项数为0,1,2,3,4,5,6··化为二进制0,1,10,11,100,101··于是可以发现二进制上为1的,S集合中相对应的项则有出现,但是项数是从0开始的,所以程序取的n要减去1。题目要求n是最多19位的数,预计3的次幂可能会很大,采用预先生成3的64以下的各次幂。
生成方法如下:(需要调用大数模板)
以下是本题的代码:
- FZU 1084 Three powers
- pku_1906 Three powers
- POJ 1906 Three Powers
- UVa10669 - Three powers
- ZOJ 2371 数论Three powers
- FZU - 1981 Three kingdoms
- Uva16009 POJ 1906 Three Powers 数论 玄学找规律题 高精
- FZU
- FZU
- FZU
- FZU
- FZU
- FZU
- FZU
- FZU
- FZU
- FZU
- FZU
- Oracle 10g 异常:ORA-01092: ORACLE 实例终止。强制断开连接 解决方案
- Chrome源码剖析 【序】 && 【一】
- windows 下的符号链接Junction
- 我被OpenMP时里这时间搞晕了
- Ycnd 2D教程1---初始化引擎的方法
- FZU 1084 Three powers
- 海量小文件存储
- 各种小代码片段2
- 我对CSDN的评价
- 什么是批处理
- 几个少见的宏以及其作用
- Swing 框架之Renderer(一)
- Java中遭遇NaN
- Swing框架之Renderer(二)