Submission #2545187


Source Code Expand

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

    private static final int MOD = 1_000_000_007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        System.out.println( solve(N) );
    }

    private static long solve(int N) {
        // primes under 31
        int[] primes = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
        Map<Integer, Integer> primeCounts = new HashMap<>();

        for (int n = 2; n <= N; n++) {
            int remain = n;
            for (int p : primes) {
                Result result = countFactor(remain, p);
                if( result.cnt > 0 ) {
                    incrementPrime(p, result.cnt, primeCounts);
                    remain = result.remain;
                }
            }

            if( remain != 1 ) {
                incrementPrime(remain, 1, primeCounts);
            }
        }

        // 各素数の組み合わせ
        long ans = 1;
        for (Integer cnt : primeCounts.values()) {
            ans = (ans * (cnt + 1)) % MOD;
        }
        return ans;
    }

    private static Result countFactor(int n, int f) {
        int cnt = 0;
        while(true) {
            if( n % f == 0 ) {
                n = n / f;
                cnt++;
            } else {
                break;
            }
        }
        return new Result(cnt, n);
    }

    private static void incrementPrime(int p, int cnt, Map<Integer, Integer> countPrimes) {
        if( countPrimes.containsKey(p) ) {
            countPrimes.put(p, countPrimes.get(p) + cnt);
        } else {
            countPrimes.put(p, cnt);
        }
    }

    private static class Result {
        private final int cnt;
        private final int remain;

        public Result(int cnt, int remain) {
            this.cnt = cnt;
            this.remain = remain;
        }
    }
}

Submission Info

Submission Time
Task C - Factors of Factorial
User kusomushi
Language Java8 (OpenJDK 1.8.0)
Score 300
Code Size 2000 Byte
Status AC
Exec Time 105 ms
Memory 21204 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 10
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All sample_01.txt, sample_02.txt, sample_03.txt, subtask_1_certain_01.txt, subtask_1_certain_02.txt, subtask_1_certain_03.txt, subtask_1_certain_04.txt, subtask_1_rand_01.txt, subtask_1_rand_02.txt, subtask_1_rand_03.txt
Case Name Status Exec Time Memory
sample_01.txt AC 94 ms 19284 KB
sample_02.txt AC 94 ms 18892 KB
sample_03.txt AC 99 ms 19024 KB
subtask_1_certain_01.txt AC 93 ms 20688 KB
subtask_1_certain_02.txt AC 94 ms 18640 KB
subtask_1_certain_03.txt AC 99 ms 19668 KB
subtask_1_certain_04.txt AC 100 ms 21204 KB
subtask_1_rand_01.txt AC 98 ms 20564 KB
subtask_1_rand_02.txt AC 100 ms 19280 KB
subtask_1_rand_03.txt AC 105 ms 18644 KB