Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define int long long
- #define uint unsigned long long
- #define double long double
- #pragma GCC optimize("O3,Ofast,no-stack-protector,fast-math,unroll-loops")
- using namespace std;
- int pasc[501][501];
- void init() {
- pasc[1][1] = 1;
- for (int i = 2; i <= 500; i++) {
- pasc[i][1] = 1;
- pasc[i][i] = 1;
- for (int j = 2; j < i; j++) {
- pasc[i][j] = pasc[i - 1][j - 1] + pasc[i - 1][j];
- pasc[i][j] %= 1000000000000;
- }
- }
- }
- bool solve(int i, int n, int z, bool show) {
- int x = 0;
- int q = 0;
- int r = 1;
- int k = 1;
- if (show) {
- cout << "Case #" << i << ":\n";
- }
- while (x < n) {
- q++;
- x += pasc[r][k];
- if (show) {
- cout << r << ' ' << k << '\n';
- }
- if (r < z) {
- r++;
- } else {
- bool cond;
- if (r == k) {
- cond = (x + pasc[r + 1][k + 1] <= n);
- } else {
- cond = (x + pasc[r + 1][k + 1] <= n);
- }
- if (cond) {
- r++;
- k++;
- } else {
- k++;
- }
- }
- }
- return q <= 499 && x == n;
- }
- signed main() {
- init();
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- int t;
- cin >> t;
- for (int i = 1; i <= t; i++) {
- int n;
- cin >> n;
- for (int z = 16; z >= 1; z--) {
- if (solve(i, n, z, 0)) {
- solve(i, n, z, 1);
- break;
- }
- }
- }
- fflush(stdout);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement