Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import static java.util.Arrays.binarySearch;
- import static java.util.Arrays.deepToString;
- import static java.util.Arrays.sort;
- import java.io.*;
- import java.util.*;ф
- public class lcm_nn_2 {
- static final int MOD = 1000000007;
- static int[] getDivisors(int n) {
- List<Integer> d = new ArrayList<Integer>();
- for (long i = 1; i * i <= n; i++) {
- if (n % i != 0) {
- continue;
- }
- d.add((int) i);
- if (i * i != n) {
- d.add((int) (n / i));
- }
- }
- int[] ret = new int[d.size()];
- for (int i = 0; i < d.size(); i++) {
- ret[i] = d.get(i);
- }
- sort(ret);
- return ret;
- }
- static int lcm(int a, int b) {
- return a / gcd(a, b) * b;
- }
- static int gcd(int a, int b) {
- return b == 0 ? a : gcd(b, a % b);
- }
- static void solve() throws Exception {
- int n = nextInt();
- int k = nextInt();
- out.println(solve(n, k));
- }
- static int solve(int n, int k) {
- int[] d = getDivisors(n);
- int[][] dp = new int[k + 1][d.length];
- int[][] lcm = new int[d.length][d.length];
- for (int i = 0; i < d.length; i++) {
- for (int j = i; j < d.length; j++) {
- lcm[i][j] = lcm[j][i] = binarySearch(d, lcm(d[i], d[j]));
- }
- }
- dp[0][0] = 1;
- for (int i = 0; i < d.length; i++) {
- for (int j = 0; j < k; j++) {
- for (int t = 0; t < d.length; t++) {
- int z = lcm[i][t];
- dp[j + 1][z] += dp[j][t];
- if (dp[j + 1][z] >= MOD) {
- dp[j + 1][z] -= MOD;
- }
- }
- }
- }
- return dp[k][d.length - 1];
- }
- static BufferedReader br;
- static StringTokenizer st;
- static PrintWriter out;
- static void debug(Object... a) {
- System.err.println(deepToString(a));
- }
- static int nextInt() throws IOException {
- return Integer.parseInt(next());
- }
- static String next() throws IOException {
- while (st == null || !st.hasMoreTokens()) {
- String line = br.readLine();
- if (line == null) {
- return null;
- }
- st = new StringTokenizer(line);
- }
- return st.nextToken();
- }
- static long nextLong() throws IOException {
- return Long.parseLong(next());
- }
- static double nextDouble() throws IOException {
- return Double.parseDouble(next());
- }
- public static void main(String[] args) {
- try {
- File file = new File("lcm.in");
- InputStream input = System.in;
- OutputStream output = System.out;
- if (file.canRead()) {
- input = (new FileInputStream(file));
- output = (new PrintStream("lcm.out"));
- }
- br = new BufferedReader(new InputStreamReader(input));
- out = new PrintWriter(output);
- solve();
- out.close();
- br.close();
- } catch (Throwable e) {
- e.printStackTrace();
- System.exit(1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement