2013
11-10

# Three powers

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.

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.

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.

1
7
14
783
1125900981634049
0


{ }
{ 3, 9 }
{ 1, 9, 27 }
{ 3, 9, 27, 6561, 19683 }
{ 59049, 3486784401, 205891132094649, 717897987691852588770249 }


//* @author:
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
public static void main(String[]args){
BigInteger dat[]=new BigInteger[100];
dat[0]=BigInteger.ONE;
BigInteger tr=new BigInteger("3");
for(int i=1;i< 100;i++){
dat[i]=dat[i-1].multiply(tr);
}
long N;
int t;
boolean first;
Scanner cin=new Scanner(System.in);
while(cin.hasNext()){
N=cin.nextLong();
if(N==0) break;
N--;
t=0;
first=true;
System.out.print("{");
while(N>0){
if(N%2==1){
if(first){
first=false;
System.out.print(" "+dat[t]);
}
else System.out.print(", "+dat[t]);
}
t++;
N/=2;
}
System.out.println(" }");
}
}
}

1. Good task for the group. Hold it up for every yeara??s winner. This is a excellent oppotunity for a lot more enhancement. Indeed, obtaining far better and much better is constantly the crucial. Just like my pal suggests on the truth about ab muscles, he just keeps obtaining much better.

2. bottes vernies blanches

I appreciate the efforts you men and women place in to share blogs on such sort of matters, it was certainly useful. Keep Posting!

3. /*
* =====================================================================================
*
* Filename: 1366.cc
*
* Description:
*
* Version: 1.0
* Created: 2014年01月06日 14时52分14秒
* Revision: none
* Compiler: gcc
*
* Author: Wenxian Ni (Hello World~), niwenxianq@qq.com
* Organization: AMS/ICT
*
* =====================================================================================
*/

#include
#include

using namespace std;

int main()
{
stack st;
int n,i,j;
int test;
int a[100001];
int b[100001];
while(cin>>n)
{
for(i=1;i>a[i];
for(i=1;i>b[i];
//st.clear();
while(!st.empty())
st.pop();
i = 1;
j = 1;

while(in)
break;
}
while(!st.empty()&&st.top()==b[j])
{
st.pop();
j++;
}
}
if(st.empty())
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}