Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

java轻轻的水过

Posted by Ly86 at 2010-05-10 21:19:59 on Problem 1906
import java.math.*;
import java.io.*;
import java.util.*;
class Main{
	
	
	public static void main(String args[]){
		long n;
		boolean sign[] = new boolean[70];
		int sum ;
		Scanner cin = new Scanner(System.in);
		while(true){
		n = cin.nextLong();
		sum  = 0;
		Arrays.fill(sign,false);	
		if(n == 0) break;
		n--;
		if(n == 0) {System.out.println("{ }");continue;}
       int l=0;
		while(n>0){
			if(n%2==1) {sign[l] = true;sum++;} 
			n=n/2;
			l++;
			
		}
		
		System.out.print("{ ");
		for(int i=0;i<64;i++)
			if(sign[i]) {
				System.out.print(BigInteger.valueOf(3).pow(i));
				sum--;
				if(sum!=0) System.out.print(", ");
			}
		System.out.println(" }");
		}
	}
	
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator