Created
December 14, 2015 08:54
-
-
Save kumamotone/ff388f4b221bfc7d1b0c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import java.io.BufferedReader; | |
import java.io.InputStreamReader; | |
import java.math.*; | |
public class Main { | |
// StringUtils#strip(String str, String stripChars) From ApacheCommons | |
public static String stripStart(String str, String stripChars) { | |
int strLen; | |
if (str == null || (strLen = str.length()) == 0) { | |
return str; | |
} | |
int start = 0; | |
if (stripChars == null) { | |
while ((start != strLen) && Character.isWhitespace(str.charAt(start))) { | |
start++; | |
} | |
} else if (stripChars.length() == 0) { | |
return str; | |
} else { | |
while ((start != strLen) && (stripChars.indexOf(str.charAt(start)) != -1)) { | |
start++; | |
} | |
} | |
return str.substring(start); | |
} | |
public static String stripEnd(String str, String stripChars) { | |
int end; | |
if (str == null || (end = str.length()) == 0) { | |
return str; | |
} | |
if (stripChars == null) { | |
while ((end != 0) && Character.isWhitespace(str.charAt(end - 1))) { | |
end--; | |
} | |
} else if (stripChars.length() == 0) { | |
return str; | |
} else { | |
while ((end != 0) && (stripChars.indexOf(str.charAt(end - 1)) != -1)) { | |
end--; | |
} | |
} | |
return str.substring(0, end); | |
} | |
public static void main(String[] args) throws Exception { | |
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | |
String line = br.readLine(); | |
long n = Long.parseLong(line); | |
BigInteger b = BigInteger.ONE; | |
for(int i=2; i<=n; i++) { | |
b = b.multiply(BigInteger.valueOf(i)); | |
String s = b.toString(); | |
String ss = stripEnd(s,"0"); | |
String sss = (ss.length() >= 15) ? ss.substring(ss.length()-15) : ss; | |
String ssss = stripStart(sss,"0"); | |
b = new BigInteger(ssss); | |
} | |
String s = b.toString(); | |
String ss = stripEnd(s,"0"); | |
String sss = (ss.length() >= 9) ? ss.substring(ss.length()-9) : ss; | |
String ssss = stripStart(sss,"0"); | |
System.out.println(ssss); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment