題意:
(from luckycat)
解 法: 大數運算。
TAG: BigNum,
注意:
程式碼:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Tittle: 10220 - I Love Big Numbers ! | |
* Author: Cheng-Shih, Wong | |
* Date: 2015/05/21 | |
*/ | |
import java.util.*; | |
import java.math.*; | |
public class Main { | |
public static void main( String[] args ) { | |
int n, ans; | |
Scanner input = new Scanner( System.in ); | |
BigInteger[] fact = new BigInteger[1005]; | |
String str = null; | |
// initialization | |
fact[0] = BigInteger.ONE; | |
for( int i=1; i<=1000; ++i ) | |
fact[i] = fact[i-1].multiply( BigInteger.valueOf(i) ); | |
// input | |
while( input.hasNext() ) { | |
n = input.nextInt(); | |
// solve | |
str = fact[n].toString(); | |
ans = 0; | |
for( int i=0; i<str.length(); ++i ) | |
ans += str.charAt(i)-'0'; | |
// output | |
System.out.println(ans); | |
} | |
input.close(); | |
} | |
} |
沒有留言:
張貼留言
任何意見都樂意傾聽