1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
| public static int MOD = 1000000007;
long[][] c;
public void getC(int n, int m) { c = new long[n+1][m+1]; for (int i = 1;i<=n;i++) { c[i][0] = 1; if (i <=m) { c[i][i] = 1; } for (int j = 1;j<m && j < i;j++) { c[i][j] = c[i-1][j-1] + c[i-1][j]; c[i][j] %= MOD; } } }
public int idealArrays(int n, int maxValue) { Set<Integer>[] divNums = new Set[maxValue+1]; for (int i = 0;i<=maxValue;i++) { divNums[i]= new HashSet<>(); }
for (int value = 2;value<=maxValue;value++) { divNums[value].add(1); for (int div = 2; div * div <= value;div++) { if (value % div == 0) { divNums[value].add(div); divNums[value].add(value/div); } } }
int maxDivCount = 0; int value = maxValue; while (value > 0) { value /= 2; maxDivCount++; }
long[][] dp = new long[maxDivCount+1][maxValue+1];
for (value = 0; value <=maxValue;value++) { for (int i = 1; i <=maxDivCount;i++) { if (i==1) { dp[i][value] = 1; continue; }
for (int div : divNums[value]) { dp[i][value] += dp[i-1][div]; dp[i][value] %= MOD; } } }
getC(n-1, maxDivCount);
long sum = 0; for (value = 1;value <= maxValue;value++) { for (int divCount = 1; divCount <=maxDivCount;divCount++) { sum += c[n-1][divCount-1] * dp[divCount][value]; sum %= MOD; } } return (int)sum; }
|