Skip to content

Instantly share code, notes, and snippets.

@nomuken
Last active August 29, 2015 14:07
Show Gist options
  • Save nomuken/998d24857c8963622114 to your computer and use it in GitHub Desktop.
Save nomuken/998d24857c8963622114 to your computer and use it in GitHub Desktop.
頑張った(typoは気にしない主義)
import java.math.BigDecimal;
import java.math.MathContext;
import java.util.ArrayList;
public class Tes{
public static void main(String[] args){
int error = 18;
BigDecimal powAns = new BigDecimal(123);
BigDecimal ans = new BigDecimal("0");
ArrayList<Double> range = new ArrayList<Double>();
for(int i=1;error>=i;i++){
range.add(new Double(mutiString(i)));
}
for(Double stp : range) {
BigDecimal rng = new BigDecimal(stp.doubleValue());
for (; 1 > ans.multiply(powAns, MathContext.DECIMAL128).doubleValue(); ans = ans.add(rng));
ans = ans.subtract(rng);
}
ans=ans.add(new BigDecimal(range.get(range.size()-1)));
System.out.println(ans.doubleValue());
}
public static String mutiString(int n){
String ans = "0.";
for(int i=0;n-1>i;i++)ans+="0";
ans+="1";
return ans;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment