Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int lastDigitDiffZero(long n) {
- long a = fact(n);
- if(a < 10000) {
- long last= a % 10;
- while (a % 10 == 0) {
- a /= 10;
- last =a%10;
- }
- return (int)last;
- }
- BigInteger f = factorial(n);
- BigInteger b2 = new BigInteger("10");
- BigInteger b3 = BigInteger.ZERO;
- while (f.mod(new BigInteger("10")).equals(BigInteger.ZERO)) {
- f = f.divide(b2);
- b3 = f.mod(new BigInteger("10"));
- }
- return b3.intValue();
- }
- BigInteger factorial(long n) {
- BigInteger result = BigInteger.ONE;
- for (; n > 1; n--) {
- result = result.multiply(BigInteger.valueOf(n));
- }
- return result;
- }
- int fact(long n) {
- int f = 0;
- for (int c = 1; c <= n; c++) {
- f *= c;
- }
- return f;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement