Skip to content

Commit

Permalink
20240307 tsreaper's submission (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsreaper authored Mar 7, 2024
1 parent 9f81548 commit 7383c66
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <bits/stdc++.h>
using namespace std;

double power(double a, int b) {
double y = 1;
for (; b; b >>= 1) {
if (b & 1) y *= a;
a *= a;
}
return y;
}

int main() {
int m, n; scanf("%d%d", &m, &n);
double ans = 0;
for (int i = 1; i <= m; i++) {
double t = power(1.0 * i / m, n) - power(1.0 * (i - 1) / m, n);
ans += t * i;
}
printf("%.9f\n", ans);
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <bits/stdc++.h>
#define MAXB 10
#define MAXP 60
using namespace std;

vector<int> A;
long long f[MAXB + 1][MAXP][2][1 << MAXB];

long long dp(int b, int pos, int full, int bgn,int msk) {
if (pos < 0) return msk == 0;
long long ret = f[b][pos][bgn][msk];
if (!full && ret >= 0) return ret;
ret = 0;

int R = (full ? A[pos] : b - 1);
for (int i = 0; i <= R; i++) {
int nxtBgn = bgn || i > 0;
int nxtMsk = msk;
if (nxtBgn) nxtMsk ^= 1 << i;
ret += dp(b, pos - 1, full && i == R, nxtBgn, nxtMsk);
}
if (!full) f[b][pos][bgn][msk] = ret;
return ret;
}

long long solve(long long X, int b) {
A.clear();
for (; X; X /= b) A.push_back(X % b);
return dp(b, A.size() - 1, 1, 0, 0);
}

int main() {
memset(f, -1, sizeof(f));
int tcase; scanf("%d", &tcase);
while (tcase--) {
int b;
long long l, r;
scanf("%d%lld%lld", &b, &l, &r);
printf("%lld\n", solve(r, b) - solve(l - 1, b));
}
return 0;
}
2 changes: 1 addition & 1 deletion records/202403.csv
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Name, Days with Submissions, Total Submissions
Yawn_Sean,5,10
Arrogant_sword,5,6
TsReaper,5,10
TsReaper,6,12
retyrn,4,6
ncf,5,5
hum,5,10
Expand Down

0 comments on commit 7383c66

Please sign in to comment.