Check-in [7ea790dbb6]
Not logged in
Overview
SHA1 Hash:7ea790dbb68596fc2bf233d4db876d920094a4b4
Date: 2011-07-09 15:16:33
User: kinaba
Comment:8
Timelines: family | ancestors | descendants | both | trunk
Downloads: Tarball | ZIP archive
Other Links: files | file ages | manifest
Tags And Properties
Changes

Name change from from SRM/TCO8-U/1A.java to SRM/TCO8-3-U/1A.java.

Deleted SRM/TCO8-U/1A.java version [49868c43512ca5f3]

1 -import java.math.*; 2 -import java.util.*; 3 - 4 -public class ZenoDivision { 5 - static BigInteger ZERO = BigInteger.ZERO; 6 - static BigInteger ONE = BigInteger.ONE; 7 - static BigInteger TWO = BigInteger.valueOf(2); 8 - static BigInteger TEN = BigInteger.TEN; 9 - 10 - public String cycle(String a_, String b_) 11 - { 12 - BigInteger a = new BigInteger(a_); 13 - BigInteger b = new BigInteger(b_); 14 - 15 - if( b.remainder(TWO).equals(ZERO) ) 16 - return "impossible"; 17 - if( a.equals(ZERO) && b.equals(ONE) ) 18 - return "-"; 19 - if( a.equals(ONE) && b.equals(ONE) ) 20 - return "*"; 21 - 22 - int x = 1; 23 - while( !TWO.modPow(BigInteger.valueOf(x),b).equals(ONE) ) { 24 - x++; 25 - if( x >= 61 ) 26 - return "impossible"; 27 - } 28 - 29 - BigInteger z = TWO.pow(x).subtract(ONE).divide(b); 30 - String str = a.multiply(z).toString(2); 31 - while( str.length() < x ) 32 - str = "0" + str; 33 - 34 - String answer = ""; 35 - for(int i=0; i<str.length(); ++i) 36 - answer += (str.charAt(i)=='1' ? "*" : "-"); 37 - return answer; 38 - } 39 -};