QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#650262#4770. Binomial coefficientsSGColin#AC ✓38ms4256kbC++201.8kb2024-10-18 14:18:062024-10-18 14:18:07

Judging History

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

  • [2024-10-18 14:18:07]
  • 评测
  • 测评结果:AC
  • 用时:38ms
  • 内存:4256kb
  • [2024-10-18 14:18:06]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

inline ll rd() {
    ll x = 0;
    bool f = 0;
    char c = getchar();
    for (; !isdigit(c); c = getchar()) f |= (c == '-');
    for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
    return f ? -x : x;
}

#define eb emplace_back
#define all(s) (s).begin(), (s).end()
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)

double fac[31];

ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}

inline void work() {
    ll w = rd();
    vector<pll> ans;
    auto check = [&](ll n, ll m) {
        vector<ll> tmp, tmp2;
        tmp.eb(w);
        rep(i, 1, m) tmp.eb(i);
        rep(i, 1, m) {
            tmp2.clear();
            ll cur = n - i + 1;
            for (auto x : tmp) {
                ll g = gcd(x, cur);
                cur /= g; x /= g;
                if (x) tmp2.eb(x);
            }
            if (cur != 1) return;
            swap(tmp, tmp2);
        }
        for (auto x : tmp) if (x != 1) return;
        ans.eb(n, m); ans.eb(n, n - m);
    };
    rep(i, 1, 30) {
        double bound = pow(w * fac[i], 1.0 / i);
        ll L = max(i * 2ll, (ll)bound - 20);
        ll R = bound + 20;
        // cout << i << " : " << L << " " << R << endl;
        for (ll j = L; j <= R; ++j) check(j, i);
    }
    sort(all(ans));
    ans.erase(unique(all(ans)), ans.end());
    printf("%d\n", (int)ans.size());
    bool first = true;
    for (auto [x, y] : ans) {
        if (!first) putchar(' ');
        first = false;
        printf("(%lld,%lld)", x, y);
    }
    puts("");
}

int main() {
    fac[0] = 1;
    rep(i, 1, 30) fac[i] = fac[i - 1] * i;
    per(t, rd(), 1) work();
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 4256kb

input:

2
2
15

output:

1
(2,1)
4
(6,2) (6,4) (15,1) (15,14)

result:

ok 4 lines

Test #2:

score: 0
Accepted
time: 38ms
memory: 4088kb

input:

100
2
3
4
5
6
7
8
9
10
15
120
3003
24310
495918532948104
1000000000000000
210
1540
2701
7140
11628
48620
614386
705432
817190
885115
4200651
4610166
5311735
5918520
6299475
6666891
6876486
7023974
7610851
8002000
8948565
9016381
9411291
9695406
30421755
1676056044
9075135300
101766230790
13784652882...

output:

1
(2,1)
2
(3,1) (3,2)
2
(4,1) (4,3)
2
(5,1) (5,4)
3
(4,2) (6,1) (6,5)
2
(7,1) (7,6)
2
(8,1) (8,7)
2
(9,1) (9,8)
4
(5,2) (5,3) (10,1) (10,9)
4
(6,2) (6,4) (15,1) (15,14)
6
(10,3) (10,7) (16,2) (16,14) (120,1) (120,119)
8
(14,6) (14,8) (15,5) (15,10) (78,2) (78,76) (3003,1) (3003,3002)
6
(17,8) (17,9)...

result:

ok 200 lines