是这无聊的意思么? import java.math.BigInteger;public class Test { public static void main(String[] args) throws Exception { BigInteger value = new BigInteger("1"); for(int i=2; i<= 100; i++) { BigInteger b = new BigInteger("" + i); value = value.multiply(b); }
String tmp = value.toString(); long sum = 0; for(int i=0; i<tmp.length(); i++) { sum += Integer.parseInt("" + tmp.charAt(i)); } System.out.println(sum); } }
m = 1 s = 0 (1..100).each{|a| m *= a} m.to_s.each_char{|i| s += i.to_i} p s Ruby的,648, 不到1秒钟就出来结果了。
import java.math.BigInteger; public class FTest{ public static void main(String args[]){ BigInteger jc=new BigInteger(""+1); for(int i=1;i<1000;i++){ BigInteger bi=new BigInteger(i+""); jc=jc.multiply(bi); String s=jc.toString(); int sum=0; for(int j=0;j<s.length();j++){ sum+=Integer.parseInt(s.charAt(j)+""); } System.out.println(i+"\t\t"+sum); } }
import java.math.BigInteger;public class Test {
public static void main(String[] args) throws Exception {
BigInteger value = new BigInteger("1");
for(int i=2; i<= 100; i++) {
BigInteger b = new BigInteger("" + i);
value = value.multiply(b);
}
String tmp = value.toString();
long sum = 0;
for(int i=0; i<tmp.length(); i++) {
sum += Integer.parseInt("" + tmp.charAt(i));
}
System.out.println(sum);
}
}
m = 1
s = 0
(1..100).each{|a| m *= a}
m.to_s.each_char{|i| s += i.to_i}
p s
Ruby的,648, 不到1秒钟就出来结果了。
import java.math.BigInteger;
public class FTest{
public static void main(String args[]){
BigInteger jc=new BigInteger(""+1);
for(int i=1;i<1000;i++){
BigInteger bi=new BigInteger(i+"");
jc=jc.multiply(bi);
String s=jc.toString();
int sum=0;
for(int j=0;j<s.length();j++){
sum+=Integer.parseInt(s.charAt(j)+"");
}
System.out.println(i+"\t\t"+sum);
}
}
}647 6282
648 6012
649 6372
why?
计算到999就停了
http://topic.csdn.net/u/20100722/13/17c9fe5d-c044-46f9-9ebc-adc3f4ae2f6e.html