QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#129684#4546. Counting Good Arraysbatrr#AC ✓1048ms19896kbC++172.9kb2023-07-22 22:06:112023-07-22 22:06:12

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-22 22:06:12]
  • 评测
  • 测评结果:AC
  • 用时:1048ms
  • 内存:19896kb
  • [2023-07-22 22:06:11]
  • 提交

answer

#include <bits/stdc++.h>

#define f first
#define s second
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int N = 300500, inf = 1e9, mod = 1000000007;
const ll INF = 1e18;

int sum(int a, int b) {
    a += b;
    if (a >= mod)
        a -= mod;
    return a;
}

int sub(int a, int b) {
    a -= b;
    if (a < 0)
        a += mod;
    return a;
}

int mult(int a, int b) {
    return 1ll * a * b % mod;
}

int bp(int a, int b) {
    int res = 1;
    while (b) {
        if (b & 1)
            res = mult(res, a);
        a = mult(a, a);
        b >>= 1;
    }
    return res;
}

int inv(int x) {
    return bp(x, mod - 2);
}

ll dp[1000000][32];
ll dp2[1000000][32];

void solve() {
    ll n, m;
    cin >> n >> m;
    ll m2 = round(sqrt(m))+20;
    for (ll i=1;i<=m2;i++)
    {
        dp2[i][0] = 1;
        for (int j=1;j<32;j++)
        {
            dp2[i][j] = 0;
        }
        ll w = 2;
        ll y = i/w;
        for (;w*w<=i;w++)
        {
            y = i/w;
            for (int j=1;j<32;j++)
            {
                dp2[i][j] = (dp2[i][j]+dp2[y][j-1])%mod;
            }
        }
        y = i/w;
        for (;y>0;y--)
        {
            ll r = i/y+1;
            for (int j=1;j<32;j++)
            {
                dp2[i][j] = (dp2[i][j]+dp2[y][j-1]*(r-w))%mod;
            }
            w = r;
        }
    }
    for (ll i=m2;i>=1;i--)
    {
        dp[i][0] = 1;
        for (int j=1;j<32;j++)
        {
            dp[i][j] = 0;
        }
        ll x2 = m/i;
        ll w = 2;
        ll y = x2/w;
        for (;i*w*w<=m;w++)
        {
            ll i2 = i*w;
            y = x2/w;
            if (i2<=m2)
            {
                for (int j=1;j<32;j++)
                {
                    dp[i][j] = (dp[i][j]+dp[i2][j-1])%mod;
                }
            }
            else
            {
                for (int j=1;j<32;j++)
                {
                    dp[i][j] = (dp[i][j]+dp2[y][j-1])%mod;
                }
            }
        }
        y = x2/w;
        for (;y>0;y--)
        {
            ll r = x2/y+1;
            for (int j=1;j<32;j++)
            {
                dp[i][j] = (dp[i][j]+dp2[y][j-1]*(r-w))%mod;
            }
            w = r;
        }
    }
    ll A = 1;
    ll ans = mod-1;
    for (int d=0;d<=31;d++)
    {
        if (d>n) continue;
        A = A*bp(d+1,mod-2)%mod;
        A = A*(n+1-d)%mod;
        ans = (ans+dp[1][d]*A)%mod;
    }
    cout << ans << "\n";
}

int main() {
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    int t = 1;
    cin >> t;
    for (int i = 1; i <= t; i++) {
//        cout << "Case #" << i << endl;
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1048ms
memory: 19896kb

input:

1000
486 883
23 290
747 511
348 471
670 623
629 164
564 67
997 77
315 500
37 677
248 311
796 268
308 121
302 62
97 468
279 903
46 41
525 684
316 627
671 452
95 853
323 561
774 453
367 6281
34 326
89 747
427 972
557 632
828 392
763 781
131 474
309 524
705 36
902 941
159 965
771 987
3200992 5997028
97...

output:

631912873
315338027
467956819
201505516
690707212
986735216
448196901
514391677
3775328
879898834
608483694
750562807
976713610
582112886
848852999
498981245
51730220
400573309
729001874
139361567
200957321
900938122
795863017
761815049
482147929
866858692
536686424
755634093
239674386
216221570
829...

result:

ok 1000 lines